Files
NodeBB/src/controllers/posts.js

50 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
2017-03-02 16:11:11 +03:00
var async = require('async');
var posts = require('../posts');
2017-08-11 14:22:02 -04:00
var privileges = require('../privileges');
var helpers = require('./helpers');
2017-03-02 16:11:11 +03:00
var postsController = module.exports;
2017-03-02 16:11:11 +03:00
postsController.redirectToPost = function (req, res, next) {
var pid = parseInt(req.params.pid, 10);
if (!pid) {
2017-03-02 16:11:11 +03:00
return next();
}
2017-03-02 16:11:11 +03:00
async.waterfall([
function (next) {
2017-08-11 14:22:02 -04:00
async.parallel({
canRead: function (next) {
privileges.posts.can('read', pid, req.uid, next);
},
path: function (next) {
posts.generatePostPath(pid, req.uid, next);
},
}, next);
2017-03-02 16:11:11 +03:00
},
2017-08-11 14:22:02 -04:00
function (results, next) {
if (!results.canRead) {
return helpers.notAllowed(req, res);
}
if (!results.path) {
2017-03-02 16:11:11 +03:00
return next();
}
2017-08-11 14:22:02 -04:00
helpers.redirect(res, results.path);
2017-03-02 16:11:11 +03:00
},
], next);
};
2017-03-02 16:11:11 +03:00
postsController.getRecentPosts = function (req, res, next) {
async.waterfall([
function (next) {
posts.getRecentPosts(req.uid, 0, 19, req.params.term, next);
},
function (data) {
res.json(data);
},
], next);
};