mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-08 08:32:53 +01:00
feat: async/await
This commit is contained in:
@@ -1,49 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
const posts = require('../posts');
|
||||
const privileges = require('../privileges');
|
||||
const helpers = require('./helpers');
|
||||
|
||||
var posts = require('../posts');
|
||||
var privileges = require('../privileges');
|
||||
var helpers = require('./helpers');
|
||||
const postsController = module.exports;
|
||||
|
||||
var postsController = module.exports;
|
||||
|
||||
postsController.redirectToPost = function (req, res, next) {
|
||||
var pid = parseInt(req.params.pid, 10);
|
||||
postsController.redirectToPost = async function (req, res, next) {
|
||||
const pid = parseInt(req.params.pid, 10);
|
||||
if (!pid) {
|
||||
return next();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
canRead: function (next) {
|
||||
privileges.posts.can('topics:read', pid, req.uid, next);
|
||||
},
|
||||
path: function (next) {
|
||||
posts.generatePostPath(pid, req.uid, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (!results.path) {
|
||||
return next();
|
||||
}
|
||||
if (!results.canRead) {
|
||||
return helpers.notAllowed(req, res);
|
||||
}
|
||||
helpers.redirect(res, results.path);
|
||||
},
|
||||
], 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 = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
posts.getRecentPosts(req.uid, 0, 19, req.params.term, next);
|
||||
},
|
||||
function (data) {
|
||||
res.json(data);
|
||||
},
|
||||
], next);
|
||||
postsController.getRecentPosts = async function (req, res) {
|
||||
const data = await posts.getRecentPosts(req.uid, 0, 19, req.params.term);
|
||||
res.json(data);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user