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 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]]']));
|
||||
|
||||
Reference in New Issue
Block a user