mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: don't error if file required too early
Exception during run: TypeError: ttl must be positive integer or Infinity if set
at new TTLCache (/home/runner/work/NodeBB/NodeBB/node_modules/@isaacs/ttlcache/index.js:35:13)
This commit is contained in:
@@ -5,12 +5,12 @@ const meta = require('../meta');
|
|||||||
const helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
|
|
||||||
const cache = cacheCreate({
|
let cache;
|
||||||
ttl: meta.config.uploadRateLimitCooldown * 1000,
|
|
||||||
});
|
|
||||||
|
|
||||||
exports.clearCache = function () {
|
exports.clearCache = function () {
|
||||||
cache.clear();
|
if (cache) {
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.ratelimit = helpers.try(async (req, res, next) => {
|
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))) {
|
if (!meta.config.uploadRateLimitThreshold || (uid && await user.isAdminOrGlobalMod(uid))) {
|
||||||
return next();
|
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;
|
const count = (cache.get(`${req.ip}:uploaded_file_count`) || 0) + req.files.files.length;
|
||||||
if (count > meta.config.uploadRateLimitThreshold) {
|
if (count > meta.config.uploadRateLimitThreshold) {
|
||||||
return next(new Error(['[[error:upload-ratelimit-reached]]']));
|
return next(new Error(['[[error:upload-ratelimit-reached]]']));
|
||||||
|
|||||||
Reference in New Issue
Block a user