'use strict'; const extract = require('extract-zip') const config = require('config') const fs = require('fs') const path = require('path') require('../models/db') module.exports = { importZIP: function(user, zipPath) { // 1. extract zip to local storage folder // 2. read spaces.json from this folder // 3. iterate through spaces and read all their artifact jsons // 4. fixup storage paths // 5. replace creator id by user._id let relativeImportDir = 'import_'+user._id let importDir = path.resolve(config.get('storage_local_path')+'/'+config.get('storage_bucket')+'/'+relativeImportDir) if (!fs.existsSync(importDir)) { fs.mkdirSync(importDir) } extract(zipPath, {dir: importDir}, function(err) { if (err) { console.log(err) return } console.log('[import] extracted to',importDir) let spacesJson = fs.readFileSync(importDir+'/spaces.json') let spaces = JSON.parse(spacesJson) var homeFolderId = null console.log('[import] spaces:',spaces.length) // pass 1: find homefolder for (var i=0; i