refactor: less.render already returns promise

rename callback to next to match other controllers
isekai-main
Barış Soner Uşaklı 3 years ago
parent c70eaa0a34
commit 6da3239230

@ -140,7 +140,7 @@ postsController.getTopics = async function (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 page = Math.max(1, parseInt(req.query.page, 10) || 1);
@ -150,7 +150,7 @@ async function getPostsFromUserSet(template, req, res, callback) {
]);
if (!userData) {
return callback();
return next();
}
const itemsPerPage = data.type === 'topics' ? settings.topicsPerPage : settings.postsPerPage;
const start = (page - 1) * itemsPerPage;

@ -141,17 +141,11 @@ const doUnsubscribe = async (payload) => {
};
settingsController.unsubscribe = async (req, res) => {
let payload;
try {
payload = await jwtVerifyAsync(req.params.token);
const payload = await jwtVerifyAsync(req.params.token);
if (!payload || !unsubscribable.includes(payload.template)) {
return;
}
} catch (err) {
throw new Error(err);
}
try {
await doUnsubscribe(payload);
res.render('unsubscribe', {
payload: payload,

@ -20,14 +20,14 @@ const url = nconf.get('url');
const relative_path = nconf.get('relative_path');
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;
if (
(req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
!utils.isNumber(tid)
) {
return callback();
return next();
}
let postIndex = parseInt(req.params.post_index, 10) || 1;
const [
@ -51,7 +51,7 @@ topicsController.get = async function getTopic(req, res, callback) {
invalidPagination ||
(topicData.scheduled && !userPrivileges.view_scheduled)
) {
return callback();
return next();
}
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]);
};
topicsController.pagination = async function (req, res, callback) {
topicsController.pagination = async function (req, res, next) {
const tid = req.params.topic_id;
const currentPage = parseInt(req.query.page, 10) || 1;
if (!utils.isNumber(tid)) {
return callback();
return next();
}
const [userPrivileges, settings, topic] = await Promise.all([
@ -349,7 +349,7 @@ topicsController.pagination = async function (req, res, callback) {
]);
if (!topic) {
return callback();
return next();
}
if (!userPrivileges.read || !privileges.topics.canViewDeletedScheduled(topic, userPrivileges)) {

@ -4,7 +4,6 @@
const nconf = require('nconf');
const path = require('path');
const winston = require('winston');
const util = require('util');
const db = require('../database');
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) {
if (!data.customCSS) {
return;
}
const lessObject = await lessRenderAsync(data.customCSS);
const less = require('less');
const lessObject = await less.render(data.customCSS, {
compress: true,
javascriptEnabled: true,
});
data.renderedCustomCSS = lessObject.css;
}

Loading…
Cancel
Save