diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 13:05:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 13:05:21 +0200 |
| commit | 82cf40b516b5ab11c34b3642a01603ec1b590c9f (patch) | |
| tree | 4ac62bed9c471b2df5ee6c29f00071df7e2a4af2 /index.js | |
| parent | a7465a66cd49a943b725f0a3ef45d0b1511b48db (diff) | |
store open folders in localstorage
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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) ) }) |
