You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB
JavaScript

8 years ago
'use strict';
8 years ago
var async = require('async');
var posts = require('../posts');
8 years ago
var privileges = require('../privileges');
var helpers = require('./helpers');
8 years ago
var postsController = module.exports;
8 years ago
postsController.redirectToPost = function (req, res, next) {
var pid = parseInt(req.params.pid, 10);
if (!pid) {
8 years ago
return next();
}
8 years ago
async.waterfall([
function (next) {
8 years ago
async.parallel({
canRead: function (next) {
privileges.posts.can('read', pid, req.uid, next);
},
path: function (next) {
posts.generatePostPath(pid, req.uid, next);
},
}, next);
8 years ago
},
8 years ago
function (results, next) {
if (!results.canRead) {
return helpers.notAllowed(req, res);
}
if (!results.path) {
8 years ago
return next();
}
8 years ago
helpers.redirect(res, results.path);
8 years ago
},
], next);
};
8 years ago
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);
};