Files
NodeBB/src/controllers/posts.js

39 lines
727 B
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');
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) {
posts.generatePostPath(pid, req.uid, next);
},
function (path, next) {
if (!path) {
return next();
}
helpers.redirect(res, path);
},
], 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);
};