mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-09 00:36:34 +02:00
Merge branch 'develop' into activitypub
This commit is contained in:
@@ -116,7 +116,7 @@ module.exports = function (middleware) {
|
||||
}
|
||||
|
||||
try {
|
||||
await renderMethod(template, { ...res.locals.templateValues, ...options }, fn);
|
||||
await renderMethod(template, options, fn);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ const meta = require('../meta');
|
||||
const helpers = require('./helpers');
|
||||
const user = require('../user');
|
||||
|
||||
const cache = cacheCreate({
|
||||
ttl: meta.config.uploadRateLimitCooldown * 1000,
|
||||
});
|
||||
let cache;
|
||||
|
||||
exports.clearCache = function () {
|
||||
cache.clear();
|
||||
if (cache) {
|
||||
cache.clear();
|
||||
}
|
||||
};
|
||||
|
||||
exports.ratelimit = helpers.try(async (req, res, next) => {
|
||||
@@ -18,7 +18,11 @@ exports.ratelimit = helpers.try(async (req, res, next) => {
|
||||
if (!meta.config.uploadRateLimitThreshold || (uid && await user.isAdminOrGlobalMod(uid))) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!cache) {
|
||||
cache = cacheCreate({
|
||||
ttl: meta.config.uploadRateLimitCooldown * 1000,
|
||||
});
|
||||
}
|
||||
const count = (cache.get(`${req.ip}:uploaded_file_count`) || 0) + req.files.files.length;
|
||||
if (count > meta.config.uploadRateLimitThreshold) {
|
||||
return next(new Error(['[[error:upload-ratelimit-reached]]']));
|
||||
|
||||
@@ -248,7 +248,18 @@ module.exports = function (middleware) {
|
||||
};
|
||||
|
||||
middleware.buildAccountData = async (req, res, next) => {
|
||||
res.locals.templateValues = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
// use lowercase slug on api routes, or direct to the user/<lowercaseslug>
|
||||
const lowercaseSlug = req.params.userslug.toLowerCase();
|
||||
if (req.params.userslug !== lowercaseSlug) {
|
||||
if (res.locals.isAPI) {
|
||||
req.params.userslug = lowercaseSlug;
|
||||
} else {
|
||||
const newPath = req.path.replace(new RegExp(`/${req.params.userslug}`), () => `/${lowercaseSlug}`);
|
||||
return res.redirect(`${nconf.get('relative_path')}${newPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
res.locals.userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
|
||||
next();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user