summary refs log tree commit diff
path: root/api/src/middlewares/RateLimit.ts
diff options
context:
space:
mode:
authorErkin Alp Güney <erkinalp9035@gmail.com>2022-04-24 17:35:09 +0300
committerGitHub <noreply@github.com>2022-04-24 17:35:09 +0300
commit16c10c581c30e54cdb99309272f7940ea5013d4a (patch)
tree42dd3408cacc4a91d387d0be272d93d38e2879ba /api/src/middlewares/RateLimit.ts
parentPunitive rate limiting (diff)
downloadserver-16c10c581c30e54cdb99309272f7940ea5013d4a.tar.xz
fix the seconds rounding logic
Diffstat (limited to 'api/src/middlewares/RateLimit.ts')
-rw-r--r--api/src/middlewares/RateLimit.ts4
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 (