diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-10 07:18:48 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-10 07:18:48 +0100 |
| commit | 26f8a74aee3a14563d2e802b62ee70e4f4a5bcd8 (patch) | |
| tree | 5a3f83814a20f757c547e2514fed21892a012984 /bucky/app | |
| parent | 9e6b80c0321ba1fbe1c824083acbeeac7b7b94d4 (diff) | |
pull in old upload script
Diffstat (limited to 'bucky/app')
| -rw-r--r-- | bucky/app/bucky.js | 31 | ||||
| -rw-r--r-- | bucky/app/index.js | 2 | ||||
| -rw-r--r-- | bucky/app/router.js | 8 |
3 files changed, 31 insertions, 10 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 876a769..00730c5 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -77,17 +77,30 @@ var bucky = module.exports = { return } var data = { - thread: res.thread.get('id'), - parent_id: req.body.parent_id || -1, + title: req.body.title, + keyword: req.body.keyword, username: req.user.get('username'), - date: util.now(), - comment: req.body.comment, + createdate: util.now(), + lastmodified: util.now(), + size: 0, + private: false, + color: req.body.color, + viewed: 0, + revision: 'a', } - db.createComment(data).then(function(comment){ - res.comment = comment + db.createThread(data).then(function(thread){ + res.thread = thread next() }) }, + verifyFilesOrComment: function (req, res, next){ + var hasComment = req.body.comment && req.body.comment.length + var hasFile = req.files && req.files.length + if (! hasComment && ! hasFile) { + return res.sendStatus(400) + } + next() + }, /* DETAILS */ @@ -166,6 +179,12 @@ var bucky = module.exports = { /* COMMENTS */ + createOptionalComment: function(req, res, next){ + if (! req.body.comment || ! req.body.comment.length) { + return next() + } + bucky.createComment(req, res, next) + }, createComment: function (req, res, next){ if (! req.body.comment || ! req.body.comment.length) { res.json({ error: "no comment" }) diff --git a/bucky/app/index.js b/bucky/app/index.js index b88471c..95a11a8 100644 --- a/bucky/app/index.js +++ b/bucky/app/index.js @@ -13,7 +13,6 @@ var favicon = require('serve-favicon') var passport = require('passport') var sessionstore = require('sessionstore') var session = require('express-session') -var multer = require('multer') var app, server @@ -30,7 +29,6 @@ site.init = function(){ app.use(favicon(__dirname + '../../../public/favicon.ico')) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: false })) - app.use( multer({ dest:'./uploads/' }).multiple("files") ) app.use(session({ key: 'bucky.sid', diff --git a/bucky/app/router.js b/bucky/app/router.js index c8392da..134ab1d 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -5,6 +5,7 @@ var bucky = require('./bucky') var db = require('../db') var util = require('../util/util') var search = require('../search/middleware') +var multer = require('multer')({ dest:'./uploads/' }) module.exports = function(app){ app.all('*', middleware.ensureLocals) @@ -76,9 +77,12 @@ module.exports = function(app){ ) app.post("/api/thread", middleware.ensureAuthenticated, - bucky.createComment, + multer.array("files"), + bucky.verifyFilesOrComment, + bucky.createThread, +// bucky.createFiles, + bucky.createOptionalComment, function(req, res){ - // make a new thread res.json(res.thread) }) app.post("/api/thread/:id/comment", |
