diff options
author | Erkin Alp Güney <erkinalp9035@gmail.com> | 2022-04-24 17:35:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-24 17:35:09 +0300 |
commit | 16c10c581c30e54cdb99309272f7940ea5013d4a (patch) | |
tree | 42dd3408cacc4a91d387d0be272d93d38e2879ba /api/src/middlewares | |
parent | Punitive rate limiting (diff) | |
download | server-16c10c581c30e54cdb99309272f7940ea5013d4a.tar.xz |
fix the seconds rounding logic
Diffstat (limited to 'api/src/middlewares')
-rw-r--r-- | api/src/middlewares/RateLimit.ts | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/api/src/middlewares/RateLimit.ts b/api/src/middlewares/RateLimit.ts index 8368d14a..b4f32131 100644 --- a/api/src/middlewares/RateLimit.ts +++ b/api/src/middlewares/RateLimit.ts @@ -58,7 +58,7 @@ export default function rateLimit(opts: { if (offender) { let reset = offender.expires_at.getTime(); let resetAfterMs = reset - Date.now(); - let resetAfterSec = (resetAfterMs + 999) / 1000; + let resetAfterSec = Math.ceil(resetAfterMs / 1000); if (resetAfterMs <= 0) { offender.hits = 0; @@ -73,7 +73,7 @@ export default function rateLimit(opts: { reset = reset + opts.window * 1000; // each block violation pushes the expiry one full window further offender.expires_at += opts.window * 1000; resetAfterMs = reset - Date.now(); - resetAfterSec = (resetAfterMs + 999) / 1000; + resetAfterSec = Math.ceil(resetAfterMs / 1000); console.log("blocked bucket: " + bucket_id, { resetAfterMs }); return ( |