diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 03:09:00 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-06-29 03:09:00 +0200 |
| commit | 1726a81b320e92ce412c0fa2b2b05f73798cc4ee (patch) | |
| tree | eb3314621f652098ca8d046ad081b78aa89ba78d /index.js | |
| parent | 50904f4b010c417d558174005a7b4c5868e7d8d9 (diff) | |
folder browser
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 82 |
1 files changed, 66 insertions, 16 deletions
@@ -15,6 +15,7 @@ var app, server const db = require('./lib/db') var site = module.exports = {} + site.init = function(){ app = express() app.use(express.static(path.join(__dirname, './public'))) @@ -27,6 +28,71 @@ site.init = function(){ console.log('Cortex listening at http://localhost:%s', server.address().port) }) + const folders = crud(app, 'folder', db.Folder) + const files = crud(app, 'file', db.File) + const jobs = crud(app, 'job', db.Job) + const tasks = crud(app, 'task', db.Task) + + app.post('/folders/:id', upload.array('file'), function(req, res){ + // move files to data/id + console.log(req.files) + req.files.forEach( (file) => { + }) + res.send(200) + }) + + function crud(app, type_s, model){ + const type = '/' + type_s + 's/' + const type_id = type + ':id' + + const crud = db.crud(type_s, model) + + // index + 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) ) + }) + + // show + app.get(type_id, (req, res) => { + console.log('show', type, req.params.id) + crud.show(req.params.id).then( (data) => { + console.log(data) + res.json(data.toJSON()) + })// .catch( (err) => res.sendStatus(500) ) + }) + + // create + app.post(type, (req, res) => { + console.log('create', type) + crud.create(req.body).then( (data) => { + res.json(data.toJSON()) + })// .catch( () => res.sendStatus(500) ) + }) + + // update + app.put(type_id, (req, res) => { + console.log('update', type, req.params.id) + crud.update(req.body.id, req.body).then( (data) => { + res.json(data.toJSON()) + })// .catch( () => res.sendStatus(500) ) + }) + + // destroy + app.delete(type_id, (req, res) => { + console.log('destroy', type, req.params.id) + crud.destroy(req.params.id).then( (data) => { + res.json(data.toJSON()) + })// .catch( () => res.sendStatus(500) ) + }) + + return crud + } +} // app.get("/p/:id", function(req, res){ // res.sendFile("index.html", {root: './public'}) // }) @@ -51,21 +117,5 @@ site.init = function(){ // }) // }) - /* - app.post("/upload", upload.single('image'), function(req, res){ - upload.put("image", req.file, { - unacceptable: function(err){ - res.json({ error: err }) - }, - success: function(url){ - db.createImage(url).then(function(image){ - res.json(image) - }) - } - }) - }) - */ -} - site.init() |
