summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js51
1 files changed, 41 insertions, 10 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 00730c5..5198400 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -1,6 +1,7 @@
+var _ = require('lodash')
var db = require('../db')
var util = require('../util/util')
-var _ = require('lodash')
+var upload = require('../util/upload')
var bucky = module.exports = {
@@ -93,14 +94,6 @@ var bucky = module.exports = {
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 */
@@ -177,6 +170,18 @@ var bucky = module.exports = {
})
},
+ /* POSTING */
+
+ verifyFilesOrComment: function (req, res, next){
+ var hasComment = req.body.comment && req.body.comment.length
+ var hasFile = req.files && req.files.length
+ if (! hasComment && ! hasFile) {
+ console.log(">>> NO FILES OR COMMENT")
+ return res.sendStatus(400)
+ }
+ next()
+ },
+
/* COMMENTS */
createOptionalComment: function(req, res, next){
@@ -202,7 +207,33 @@ var bucky = module.exports = {
next()
})
},
-
+
+ /* FILES */
+
+ createOptionalFiles: function(req, res, next){
+ if (! req.files || ! req.files.length) {
+ return next()
+ }
+ bucky.createFiles(req, res, next)
+ },
+ createFiles: function (req, res, next){
+ if (! req.files || ! req.files.length) {
+ res.json({ error: "no files" })
+ return
+ }
+ var data = {
+ thread: res.thread.get('id'),
+ parent_id: req.body.parent_id || -1,
+ username: req.user.get('username'),
+ date: util.now(),
+ comment: req.body.comment,
+ }
+ db.createComment(data).then(function(comment){
+ res.comment = comment
+ next()
+ })
+ },
+
/* MAIL */
ensureMailboxes: function (req, res, next){