diff options
Diffstat (limited to 'bucky/app')
| -rw-r--r-- | bucky/app/bucky.js | 22 | ||||
| -rw-r--r-- | bucky/app/index.js | 4 | ||||
| -rw-r--r-- | bucky/app/router.js | 8 |
3 files changed, 30 insertions, 4 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 43799fe..008427d 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -1,5 +1,5 @@ var db = require('../db') -var util = require('../lib/util') +var util = require('../util/util') var _ = require('lodash') var bucky = module.exports = { @@ -136,6 +136,26 @@ var bucky = module.exports = { }) }, + /* COMMENTS */ + + createComment: function (req, res, next){ + if (! req.body.comment || ! req.body.comment.length) { + res.json({ error: "no comment" }) + 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){ diff --git a/bucky/app/index.js b/bucky/app/index.js index ad97526..d06b018 100644 --- a/bucky/app/index.js +++ b/bucky/app/index.js @@ -23,8 +23,8 @@ site.init = function(){ app = express() app.set('port', 5000) app.set('view engine', 'ejs') - app.set('views', path.join(__dirname, '../views')) - app.use(express.static(path.join(__dirname, '../public'))) + app.set('views', path.join(__dirname, '../../views')) + app.use(express.static(path.join(__dirname, '../../public'))) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: false })) app.use( multer({ dest:'./uploads/' }).single("file") ) diff --git a/bucky/app/router.js b/bucky/app/router.js index 7ac6599..fe7d336 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -66,8 +66,14 @@ module.exports = function(app){ }) app.post("/api/thread/:id/comment", middleware.ensureAuthenticated, + bucky.ensureThread, + // ensure thread privacy + bucky.createComment, + // add comments and files function(req, res){ - // add comments and files + res.json({ + comment: res.comment + }) }) app.delete("/api/thread/:id", middleware.ensureAuthenticated, |
