Commit e3111f36 authored by A. Koch's avatar A. Koch

allow author override in import

parent 0c74d58e
......@@ -5,10 +5,21 @@ const
{ ObjectUtil } = require('mbjs-utils'),
config = require('config')
const folder = process.env.FOLDER
const
folder = process.env.FOLDER,
authorUUID = process.env.AUTHOR_UUID,
authorName = process.env.AUTHOR_NAME
if (!folder) throw new Error('no input folder specified')
const updateAuthor = entry => {
if (!entry.author) entry.author = {}
if (typeof entry.author === 'string') entry.author = { id: entry.author }
if (authorName) entry.author.name = authorName
if (authorUUID) entry.author.id = authorUUID
return entry
}
const proc = async function (folder) {
const mapsClient = new MongoDB(
ObjectUtil.merge({ name: 'maps', logger: console },
......@@ -20,7 +31,7 @@ const proc = async function (folder) {
for (let m of maps) {
const file = await fs.readFile(path.join(folder, 'maps', m))
const entry = JSON.parse(file)
await mapsClient.create(entry)
await mapsClient.create(updateAuthor(entry))
}
const annoClient = new MongoDB(
......@@ -33,7 +44,7 @@ const proc = async function (folder) {
for (let a of annos) {
const file = await fs.readFile(path.join(folder, 'annotations', a))
const entry = JSON.parse(file)
await annoClient.create(entry)
await annoClient.create(updateAuthor(entry))
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment