diff --git a/bin/import.js b/bin/import.js deleted file mode 100755 index 6360eb2222171d17782e5cff711dc9e01359d8e1..0000000000000000000000000000000000000000 --- a/bin/import.js +++ /dev/null @@ -1,87 +0,0 @@ -const - Acl = require('acl'), - Backend = Acl.mongodbBackend, - MongoClient = require('mongodb').MongoClient, - path = require('path'), - fs = require('mz/fs'), - { MongoDB } = require('mbjs-persistence'), - { ObjectUtil } = require('mbjs-utils'), - config = require('config') - -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 }, - config.get('resources.mongodb')), - 'uuid' - ) - await mapsClient.connect() - const maps = await fs.readdir(path.join(folder, 'maps')) - for (let m of maps) { - if (m[0] === '.') continue - const file = await fs.readFile(path.join(folder, 'maps', m)) - const entry = JSON.parse(file) - const existing = await mapsClient.get(entry.uuid) - if (existing) await mapsClient.update(entry.uuid, updateAuthor(entry)) - else await mapsClient.create(updateAuthor(entry)) - } - - const annoClient = new MongoDB( - ObjectUtil.merge({ name: 'annotations', logger: console }, - config.get('resources.mongodb')), - 'uuid' - ) - await annoClient.connect() - const annos = await fs.readdir(path.join(folder, 'annotations')) - for (let a of annos) { - if (a[0] === '.') continue - const file = await fs.readFile(path.join(folder, 'annotations', a)) - const entry = JSON.parse(file) - const existing = await annoClient.get(entry.uuid) - if (existing) await annoClient.update(entry.uuid, updateAuthor(entry)) - else await annoClient.create(updateAuthor(entry)) - } - - const cfg = config.get('acl.mongodb') - cfg.logger = console - - const db = await new Promise((resolve, reject) => { - MongoClient.connect(cfg.url, function (err, client) { - if (err) return reject(err) - cfg.logger.info(`ACL connected at ${cfg.url}/${cfg.dbName}`) - const db = client.db(cfg.dbName) - resolve(db) - }) - }) - - const acl = new Acl(new Backend(db)) - const acls = await fs.readdir(path.join(folder, 'acl')) - for (let a of acls) { - if (a[0] === '.') continue - const file = await fs.readFile(path.join(folder, 'acl', a)) - const entry = JSON.parse(file) - await new Promise((resolve, reject) => { - const resource = a.replace('.json', '') - acl.allow(entry.role, resource, entry.permissions, err => { - if (err) reject(err) - else resolve() - }) - }) - } -} - -proc(folder).then(() => process.exit(0)) diff --git a/bin/migrate.js b/bin/migrate.js deleted file mode 100644 index 71f9230b707eacf40c5c04c148c2c78c0bcb1db1..0000000000000000000000000000000000000000 --- a/bin/migrate.js +++ /dev/null @@ -1,79 +0,0 @@ -const - { MongoDB } = require('mbjs-persistence'), - { ObjectUtil, uuid } = require('mbjs-utils'), - config = require('config'), - { Annotation, Map } = require('mbjs-data-models/src/models') - -const - timelinePrefix = 'https://app.motionbank.org/piecemaker/timelines/', - gridPrefix = 'https://app.motionbank.org/mosys/grids/' - -const newPrefix = 'http://id.motionbank.org/' - -const proc = async function () { - console.log('MAPS\n--------------------------\n\n') - const mapsClient = new MongoDB( - ObjectUtil.merge({ name: 'maps', logger: console }, - config.get('resources.mongodb')), - 'uuid' - ) - await mapsClient.connect() - const maps = await mapsClient.find({}) - for (let map of maps) { - Object.keys(map).forEach(key => { - if (key[0] === '_') map[key] = undefined - }) - if (typeof map.author === 'string') { - map.author = { id: map.author } - console.log('updating author to', map.author) - } - const mi = new Map(map) - await mapsClient.update(mi.uuid, mi.toObject(), {}) - } - - console.log('ANNOTATIONS\n-------------------\n\n') - const annoClient = new MongoDB( - ObjectUtil.merge({ name: 'annotations', logger: console }, - config.get('resources.mongodb')), - 'uuid' - ) - await annoClient.connect() - const annos = await annoClient.find({}) - for (let anno of annos) { - Object.keys(anno).forEach(key => { - if (key[0] === '_') anno[key] = undefined - }) - if (typeof anno.author === 'string') { - anno.author = { id: anno.author } - console.log('updating author to', anno.author) - } - if (anno.target && typeof anno.target.id === 'string' && anno.target.id.indexOf(timelinePrefix) === 0) { - anno.target.id = anno.target.id.replace(timelinePrefix, `${newPrefix}maps/`) - console.log('updating timeline target to', anno.target.id) - } - if (anno.target && typeof anno.target.id === 'string' && anno.target.id.indexOf(gridPrefix) === 0) { - anno.target.id = anno.target.id.replace(gridPrefix, `${newPrefix}maps/`) - console.log('updating grid target to', anno.target.id) - } - if (anno.target && anno.target.type === 'Video' && typeof anno.target.id === 'string' && uuid.isUUID(anno.target.id)) { - anno.target.id = `${newPrefix}annotations/${anno.target.id}` - console.log('updating video target to', anno.target.id) - } - if (anno.target && anno.target.type === 'Annotation' && typeof anno.target.id === 'string' && uuid.isUUID(anno.target.id)) { - anno.target.id = `${newPrefix}annotations/${anno.target.id}` - console.log('updating annotation target to', anno.target.id) - } - if (anno.target && anno.target.type === 'Timeline' && typeof anno.target.id === 'string' && uuid.isUUID(anno.target.id)) { - anno.target.id = `${newPrefix}maps/${anno.target.id}` - console.log('updating timeline target to', anno.target.id) - } - if (anno.target && anno.target.type === '2DGrid' && typeof anno.target.id === 'string' && uuid.isUUID(anno.target.id)) { - anno.target.id = `${newPrefix}maps/${anno.target.id}` - console.log('updating grid target to', anno.target.id) - } - const ai = new Annotation(anno) - await annoClient.update(ai.uuid, ai.toObject(), {}) - } -} - -proc().then(() => process.exit(0))