mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: less.render already returns promise
rename callback to next to match other controllers
This commit is contained in:
@@ -140,7 +140,7 @@ postsController.getTopics = async function (req, res, next) {
|
|||||||
await getPostsFromUserSet('account/topics', req, res, next);
|
await getPostsFromUserSet('account/topics', req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getPostsFromUserSet(template, req, res, callback) {
|
async function getPostsFromUserSet(template, req, res, next) {
|
||||||
const data = templateToData[template];
|
const data = templateToData[template];
|
||||||
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ async function getPostsFromUserSet(template, req, res, callback) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!userData) {
|
if (!userData) {
|
||||||
return callback();
|
return next();
|
||||||
}
|
}
|
||||||
const itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage;
|
const itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage;
|
||||||
const start = (page - 1) * itemsPerPage;
|
const start = (page - 1) * itemsPerPage;
|
||||||
|
|||||||
@@ -141,17 +141,11 @@ const doUnsubscribe = async (payload) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
settingsController.unsubscribe = async (req, res) => {
|
settingsController.unsubscribe = async (req, res) => {
|
||||||
let payload;
|
|
||||||
try {
|
try {
|
||||||
payload = await jwtVerifyAsync(req.params.token);
|
const payload = await jwtVerifyAsync(req.params.token);
|
||||||
if (!payload || !unsubscribable.includes(payload.template)) {
|
if (!payload || !unsubscribable.includes(payload.template)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
throw new Error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await doUnsubscribe(payload);
|
await doUnsubscribe(payload);
|
||||||
res.render('unsubscribe', {
|
res.render('unsubscribe', {
|
||||||
payload: payload,
|
payload: payload,
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ const url = nconf.get('url');
|
|||||||
const relative_path = nconf.get('relative_path');
|
const relative_path = nconf.get('relative_path');
|
||||||
const upload_url = nconf.get('upload_url');
|
const upload_url = nconf.get('upload_url');
|
||||||
|
|
||||||
topicsController.get = async function getTopic(req, res, callback) {
|
topicsController.get = async function getTopic(req, res, next) {
|
||||||
const tid = req.params.topic_id;
|
const tid = req.params.topic_id;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
|
(req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
|
||||||
!utils.isNumber(tid)
|
!utils.isNumber(tid)
|
||||||
) {
|
) {
|
||||||
return callback();
|
return next();
|
||||||
}
|
}
|
||||||
let postIndex = parseInt(req.params.post_index, 10) || 1;
|
let postIndex = parseInt(req.params.post_index, 10) || 1;
|
||||||
const [
|
const [
|
||||||
@@ -51,7 +51,7 @@ topicsController.get = async function getTopic(req, res, callback) {
|
|||||||
invalidPagination ||
|
invalidPagination ||
|
||||||
(topicData.scheduled && !userPrivileges.view_scheduled)
|
(topicData.scheduled && !userPrivileges.view_scheduled)
|
||||||
) {
|
) {
|
||||||
return callback();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userPrivileges['topics:read'] || (!topicData.scheduled && topicData.deleted && !userPrivileges.view_deleted)) {
|
if (!userPrivileges['topics:read'] || (!topicData.scheduled && topicData.deleted && !userPrivileges.view_deleted)) {
|
||||||
@@ -334,12 +334,12 @@ topicsController.teaser = async function (req, res, next) {
|
|||||||
res.json(postData[0]);
|
res.json(postData[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
topicsController.pagination = async function (req, res, callback) {
|
topicsController.pagination = async function (req, res, next) {
|
||||||
const tid = req.params.topic_id;
|
const tid = req.params.topic_id;
|
||||||
const currentPage = parseInt(req.query.page, 10) || 1;
|
const currentPage = parseInt(req.query.page, 10) || 1;
|
||||||
|
|
||||||
if (!utils.isNumber(tid)) {
|
if (!utils.isNumber(tid)) {
|
||||||
return callback();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const [userPrivileges, settings, topic] = await Promise.all([
|
const [userPrivileges, settings, topic] = await Promise.all([
|
||||||
@@ -349,7 +349,7 @@ topicsController.pagination = async function (req, res, callback) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!topic) {
|
if (!topic) {
|
||||||
return callback();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userPrivileges.read || !privileges.topics.canViewDeletedScheduled(topic, userPrivileges)) {
|
if (!userPrivileges.read || !privileges.topics.canViewDeletedScheduled(topic, userPrivileges)) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const pubsub = require('../pubsub');
|
const pubsub = require('../pubsub');
|
||||||
@@ -237,22 +236,15 @@ function ensureInteger(data, field, min) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lessRender(string, callback) {
|
|
||||||
const less = require('less');
|
|
||||||
less.render(string, {
|
|
||||||
compress: true,
|
|
||||||
javascriptEnabled: true,
|
|
||||||
}, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
const lessRenderAsync = util.promisify(lessRender);
|
|
||||||
|
|
||||||
async function saveRenderedCss(data) {
|
async function saveRenderedCss(data) {
|
||||||
if (!data.customCSS) {
|
if (!data.customCSS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const less = require('less');
|
||||||
const lessObject = await lessRenderAsync(data.customCSS);
|
const lessObject = await less.render(data.customCSS, {
|
||||||
|
compress: true,
|
||||||
|
javascriptEnabled: true,
|
||||||
|
});
|
||||||
data.renderedCustomCSS = lessObject.css;
|
data.renderedCustomCSS = lessObject.css;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user