mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-02 05:40:43 +01:00
fix: logic is hard
This commit is contained in:
committed by
Andrew Rodrigues
parent
bc0ca61c6a
commit
4dd3844680
@@ -17,7 +17,8 @@ module.exports = function (middleware) {
|
||||
}
|
||||
|
||||
const count = (cache.peek(`${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]]']));
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,9 @@ describe('Upload Controllers', () => {
|
||||
// why / 2? see: helpers.uploadFile for a weird quirk where we actually upload 2 files per upload in our tests.
|
||||
async.timesSeries(meta.config.uploadRateLimitThreshold / 2, (i, next) => {
|
||||
helpers.uploadFile(`${nconf.get('url')}/api/post/upload`, path.join(__dirname, '../test/files/503.html'), {}, jar, csrf_token, (err, res, body) => {
|
||||
console.log('limit upload', i, res.statusCode, meta.config.uploadRateLimitThreshold, Date.now());
|
||||
if (i + 1 > meta.config.uploadRateLimitThreshold / 2) {
|
||||
console.log('limit upload', i, res.statusCode, meta.config.uploadRateLimitThreshold, i + 1 > meta.config.uploadRateLimitThreshold / 2, Date.now());
|
||||
|
||||
if (i + 1 >= meta.config.uploadRateLimitThreshold / 2) {
|
||||
assert.strictEqual(res.statusCode, 500);
|
||||
assert.strictEqual(body.error, '[[error:upload-ratelimit-reached]]');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user