diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-12 04:41:13 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-12 04:41:13 +0100 |
| commit | 041efed20500c145a639d8303c2a0e770bba4552 (patch) | |
| tree | 8a8c00ac93589036b1b917a8f3e58e06670e1f33 /bucky/app | |
| parent | d4ece4ab1f461653c53bb56f23406c553ea78dd3 (diff) | |
hoot order!
Diffstat (limited to 'bucky/app')
| -rw-r--r-- | bucky/app/bucky.js | 25 | ||||
| -rw-r--r-- | bucky/app/router.js | 29 |
2 files changed, 43 insertions, 11 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 6ec76a0..41c3bff 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -158,7 +158,6 @@ var bucky = module.exports = { next() }) }, - ensureCommentsForThread: function (req, res, next){ db.getCommentsForThread(res.thread.get('id')).then(function(comments){ res.comments = comments || [] @@ -180,6 +179,30 @@ var bucky = module.exports = { res.thread.set('lastmodified', util.now()) res.thread.save().then( () => next() ) }, + updateThreadSettings: function (req, res, next){ + var title = util.sanitize(req.body.title || "") + if (! title || ! title.length) { + return res.sendStatus(500) + } + var keyword = util.sanitize(req.body.keyword || "") + var settings + if (typeof req.body.settings === 'object') { + try { + settings = JSON.stringify(req.body.settings) + } catch(e) { + } + } + if (! settings) { + return res.sendStatus(500) + } + res.thread.set('title', title) + res.thread.set('keyword', keyword) + res.thread.set('color', util.sanitize(req.body.color || 'blue')) + res.thread.set('revision', res.thread.get('revision')+1) + res.thread.set('settings', settings) + res.thread.save().then( () => next() ) + }, + destroyThread: function (req, res, next) { console.log(">>> destroying thread", res.thread.get('id')) var commentPromises = res.comments.map((comment) => { diff --git a/bucky/app/router.js b/bucky/app/router.js index bac5e42..2e690fb 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -128,6 +128,25 @@ module.exports = function(app){ function(req, res){ res.json(res.thread) }) + app.put("/api/thread/:id", + middleware.ensureAuthenticated, + bucky.ensureThread, + bucky.checkThreadPrivacy, + bucky.updateThreadSettings, + function(req, res){ + res.json({ status: 'ok' }) + }) + app.delete("/api/thread/:id", + middleware.ensureAuthenticated, + bucky.ensureThread, + bucky.checkThreadPrivacy, + bucky.ensureCommentsForThread, + bucky.ensureFilesForThread, + bucky.destroyThread, + function(req, res){ + res.sendStatus(200) + }) + app.post("/api/thread/:id/comment", middleware.ensureAuthenticated, bucky.ensureThread, @@ -168,16 +187,6 @@ module.exports = function(app){ function(req, res){ res.sendStatus(200) }) - app.delete("/api/thread/:id", - middleware.ensureAuthenticated, - bucky.ensureThread, - bucky.checkThreadPrivacy, - bucky.ensureCommentsForThread, - bucky.ensureFilesForThread, - bucky.destroyThread, - function(req, res){ - res.sendStatus(200) - }) app.get("/search/", middleware.ensureAuthenticated, |
