From 82cf40b516b5ab11c34b3642a01603ec1b590c9f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 29 Jun 2017 13:05:21 +0200 Subject: store open folders in localstorage --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index b92696f..c380e87 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,13 @@ site.init = function(){ console.log('Cortex listening at http://localhost:%s', server.address().port) }) - const api_folders = crud(app, 'folder', db.Folder) + const api_folders = crud(app, 'folder', db.Folder, { + afterCreate: (folder) => { + fs.mkdir('public/data/' + folder.id + '/', function(){ + console.log('created folder', folder.id, folder.name) + }) + } + }) const api_files = crud(app, 'file', db.File) const api_jobs = crud(app, 'job', db.Job) const api_tasks = crud(app, 'task', db.Task) @@ -39,7 +45,7 @@ site.init = function(){ ( req.files || [] ).forEach( (file) => { loaded[file.filename] = false const fn = file.originalname - fs.rename(file.path, 'public/data/' + req.params.id + '/' + fn, function(){ + fs.rename(file.path, 'public/data/' + req.params.id + '/' + fn, function(err){ api_files.create({ // table.string('username') 'folder_id': req.params.id, @@ -60,7 +66,8 @@ site.init = function(){ }) }) - function crud(app, type_s, model){ + function crud(app, type_s, model, callbacks){ + callbacks = callbacks || {} const type = '/' + type_s + 's/' const type_id = type + ':id' @@ -70,7 +77,6 @@ site.init = function(){ app.get(type, (req, res) => { console.log('index', type) crud.index(req.query).then( (data) => { - // console.log(data) res.json(data ? data.toJSON() : []) }) // }).catch( () => res.sendStatus(500) ) @@ -90,6 +96,7 @@ site.init = function(){ console.log('create', type) crud.create(req.body).then( (data) => { res.json(data.toJSON()) + callbacks.afterCreate && callbacks.afterCreate(data.toJSON()) })// .catch( () => res.sendStatus(500) ) }) -- cgit v1.2.3-70-g09d2