summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js15
1 files changed, 11 insertions, 4 deletions
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) )
})