summary refs log tree commit diff
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
commit8769bb2868d1a48a7da34fc0d7f6152a51ea37c3 (patch)
tree7a13b603b80c51aac291a1fdf0aec151c9668884
parentPunitive rate limiting (diff)
downloadserver-8769bb2868d1a48a7da34fc0d7f6152a51ea37c3.tar.xz
fix the seconds rounding logic
-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 (