mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 07:40:43 +01:00
32 lines
745 B
JavaScript
32 lines
745 B
JavaScript
'use strict';
|
|
|
|
const posts = require('../posts');
|
|
const privileges = require('../privileges');
|
|
const helpers = require('./helpers');
|
|
|
|
const postsController = module.exports;
|
|
|
|
postsController.redirectToPost = async function (req, res, next) {
|
|
const pid = parseInt(req.params.pid, 10);
|
|
if (!pid) {
|
|
return next();
|
|
}
|
|
|
|
const [canRead, path] = await Promise.all([
|
|
privileges.posts.can('topics:read', pid, req.uid),
|
|
posts.generatePostPath(pid, req.uid),
|
|
]);
|
|
if (!path) {
|
|
return next();
|
|
}
|
|
if (!canRead) {
|
|
return helpers.notAllowed(req, res);
|
|
}
|
|
helpers.redirect(res, path);
|
|
};
|
|
|
|
postsController.getRecentPosts = async function (req, res) {
|
|
const data = await posts.getRecentPosts(req.uid, 0, 19, req.params.term);
|
|
res.json(data);
|
|
};
|