From 041efed20500c145a639d8303c2a0e770bba4552 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 12 Dec 2017 04:41:13 +0100 Subject: hoot order! --- bucky/app/bucky.js | 25 ++++++++++++++++++++++++- bucky/app/router.js | 29 +++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) (limited to 'bucky/app') 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, -- cgit v1.2.3-70-g09d2