mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-09 20:08:32 +03:00
Compare commits
1 Commits
topic/cust
...
feature/ve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b65c4ad2e2 |
@@ -30,10 +30,10 @@ export default ({ config, controller }) => {
|
||||
success: msg
|
||||
})
|
||||
)
|
||||
.catch(err => {
|
||||
.catch(err =>
|
||||
res.status(404)
|
||||
.send({ error: err.message, err })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
api.get('/:sheet/:tab/:resource/:frag', (req, res) => {
|
||||
|
||||
@@ -6,6 +6,7 @@ function prefixedTabs (prefix, cfg) {
|
||||
return {
|
||||
[`${prf('events')}export_events`]: BP.deeprows,
|
||||
[`${prf('associations')}export_associations`]: BP.deeprows,
|
||||
[`${prf('editorials')}export_editorials`]: BP.deeprows,
|
||||
[`${prf('sources')}export_sources`]: BP.deepids,
|
||||
[`${prf('sites')}export_sites`]: BP.rows
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import copy from '../copy/en'
|
||||
|
||||
/**
|
||||
* Controller class
|
||||
* Controller
|
||||
*
|
||||
*/
|
||||
class Controller {
|
||||
|
||||
@@ -217,10 +217,7 @@ class GsheetFetcher extends Fetcher {
|
||||
})
|
||||
.then(this._buildBlueprintsAsync())
|
||||
.then(() => true)
|
||||
.catch((err) => {
|
||||
console.log(`Error fetching gsheets: ${err.message} `)
|
||||
return false
|
||||
})
|
||||
.catch(() => false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from 'path'
|
||||
import fs from 'fs'
|
||||
import R from 'ramda'
|
||||
|
||||
const defaultBlueprint = {
|
||||
export const defaultBlueprint = {
|
||||
name: null,
|
||||
sheet: {
|
||||
name: null,
|
||||
@@ -11,11 +11,11 @@ const defaultBlueprint = {
|
||||
resources: {}
|
||||
}
|
||||
|
||||
const defaultResource = {
|
||||
export const defaultResource = {
|
||||
data: []
|
||||
}
|
||||
|
||||
function buildDesaturated (sheetId, sheetName, tab, resources) {
|
||||
export function buildDesaturated (sheetId, sheetName, tab, resources) {
|
||||
const bp = R.clone(defaultBlueprint)
|
||||
bp.sheet.name = sheetName
|
||||
bp.sheet.id = sheetId
|
||||
@@ -50,25 +50,10 @@ fs.readdirSync(normalizedPath).forEach(file => {
|
||||
allBps[bpName] = buildBlueprinter(bpName, datafier)
|
||||
})
|
||||
|
||||
function deeprowsWithSchema (datafierName, schema) {
|
||||
const datafier = data => {
|
||||
const transformedData = allBps.deeprows('', '', '', data).resources.deeprows.data
|
||||
return transformedData.map(row => {
|
||||
Object.keys(schema).forEach(key => {
|
||||
row[key] = schema[key](row[key])
|
||||
})
|
||||
return row
|
||||
})
|
||||
}
|
||||
|
||||
return buildBlueprinter(`deeprows_${datafierName}`, datafier)
|
||||
}
|
||||
|
||||
// NB: revert to ES5 'module.exports' required to make blueprinters from
|
||||
// each file in blueprinters folder available for granular import from here.
|
||||
module.exports = Object.assign({
|
||||
defaultBlueprint,
|
||||
defaultResource,
|
||||
buildDesaturated,
|
||||
deeprowsWithSchema
|
||||
buildDesaturated
|
||||
}, allBps)
|
||||
|
||||
@@ -19,6 +19,7 @@ class StoreJson {
|
||||
|
||||
save (url, data) {
|
||||
const parts = url.split('/')
|
||||
|
||||
return fs.writeFile(
|
||||
`${STORAGE_DIRNAME}/${parts[0]}__${parts[1]}__${parts[2]}.json`,
|
||||
JSON.stringify(data)
|
||||
|
||||
@@ -12,8 +12,6 @@ const egInput1 = [
|
||||
[4, 5, 6]
|
||||
]
|
||||
|
||||
// Test default blueprint exports
|
||||
// Smoke tests
|
||||
test('defaultBlueprint exports', t => {
|
||||
const expected = {
|
||||
sheet: {
|
||||
|
||||
Reference in New Issue
Block a user