mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-12 13:28:32 +03:00
Compare commits
3 Commits
feature/ad
...
topic/cust
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db2672b630 | ||
|
|
69e54a6027 | ||
|
|
6c090549c7 |
@@ -1,7 +1,5 @@
|
|||||||
import { version } from '../../package.json'
|
import { version } from '../../package.json'
|
||||||
import fetch from 'node-fetch'
|
|
||||||
import { Router } from 'express'
|
import { Router } from 'express'
|
||||||
import { getParameterByName } from '../lib/util'
|
|
||||||
import copy from '../copy/en'
|
import copy from '../copy/en'
|
||||||
|
|
||||||
export default ({ config, controller }) => {
|
export default ({ config, controller }) => {
|
||||||
@@ -24,21 +22,6 @@ export default ({ config, controller }) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
api.get('/media/:code', (req, res) => {
|
|
||||||
const { code } = req.params
|
|
||||||
fetch(`${process.env.MEDIA_API_ENDPOINT}/${code}`, {
|
|
||||||
method: 'get',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Basic ' + new Buffer(process.env.MEDIA_AUTH_USER + ":" + process.env.MEDIA_AUTH_PWORD).toString("base64")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => res.send(data.data))
|
|
||||||
.catch(err => {
|
|
||||||
res.status(err.status || 404).send({ error: err.message })
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
api.get('/update', (req, res) => {
|
api.get('/update', (req, res) => {
|
||||||
controller
|
controller
|
||||||
.update()
|
.update()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ function prefixedTabs (prefix, cfg) {
|
|||||||
[`${prf('events')}export_events`]: BP.deeprows,
|
[`${prf('events')}export_events`]: BP.deeprows,
|
||||||
[`${prf('associations')}export_associations`]: BP.deeprows,
|
[`${prf('associations')}export_associations`]: BP.deeprows,
|
||||||
[`${prf('sources')}export_sources`]: BP.deepids,
|
[`${prf('sources')}export_sources`]: BP.deepids,
|
||||||
[`${prf('shapes')}export_shapes`]: BP.deeprows,
|
|
||||||
[`${prf('sites')}export_sites`]: BP.rows
|
[`${prf('sites')}export_sites`]: BP.rows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import path from 'path'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
|
|
||||||
export const defaultBlueprint = {
|
const defaultBlueprint = {
|
||||||
name: null,
|
name: null,
|
||||||
sheet: {
|
sheet: {
|
||||||
name: null,
|
name: null,
|
||||||
@@ -11,11 +11,11 @@ export const defaultBlueprint = {
|
|||||||
resources: {}
|
resources: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultResource = {
|
const defaultResource = {
|
||||||
data: []
|
data: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildDesaturated (sheetId, sheetName, tab, resources) {
|
function buildDesaturated (sheetId, sheetName, tab, resources) {
|
||||||
const bp = R.clone(defaultBlueprint)
|
const bp = R.clone(defaultBlueprint)
|
||||||
bp.sheet.name = sheetName
|
bp.sheet.name = sheetName
|
||||||
bp.sheet.id = sheetId
|
bp.sheet.id = sheetId
|
||||||
@@ -50,10 +50,25 @@ fs.readdirSync(normalizedPath).forEach(file => {
|
|||||||
allBps[bpName] = buildBlueprinter(bpName, datafier)
|
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
|
// NB: revert to ES5 'module.exports' required to make blueprinters from
|
||||||
// each file in blueprinters folder available for granular import from here.
|
// each file in blueprinters folder available for granular import from here.
|
||||||
module.exports = Object.assign({
|
module.exports = Object.assign({
|
||||||
defaultBlueprint,
|
defaultBlueprint,
|
||||||
defaultResource,
|
defaultResource,
|
||||||
buildDesaturated
|
buildDesaturated,
|
||||||
|
deeprowsWithSchema
|
||||||
}, allBps)
|
}, allBps)
|
||||||
|
|||||||
Reference in New Issue
Block a user