From 24658edc4514bd1ac4a7350db6639929fce4727c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 7 May 2024 22:04:21 +0800 Subject: [PATCH] fix:webui auth ratelimit --- src/webui/src/api/Auth.ts | 2 +- src/webui/src/helper/Data.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webui/src/api/Auth.ts b/src/webui/src/api/Auth.ts index b287e5ca..b09dc123 100644 --- a/src/webui/src/api/Auth.ts +++ b/src/webui/src/api/Auth.ts @@ -13,7 +13,7 @@ export const LoginHandler: RequestHandler = async (req, res) => { return; } let config = await WebUIConfig(); - if (!DataRuntime.checkLoginRate(config.loginRate)) { + if (!await DataRuntime.checkLoginRate(config.loginRate)) { res.json({ code: -1, message: 'login rate limit' diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts index ef2da3eb..3d1ec634 100644 --- a/src/webui/src/helper/Data.ts +++ b/src/webui/src/helper/Data.ts @@ -22,12 +22,14 @@ let LoginRuntime: LoginRuntimeType = { } export const DataRuntime = { checkLoginRate: async function (RateLimit: number): Promise { + LoginRuntime.LoginCurrentRate++; + //console.log(RateLimit, LoginRuntime.LoginCurrentRate, Date.now() - LoginRuntime.LoginCurrentTime); if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) { LoginRuntime.LoginCurrentRate = 0;//超出时间重置限速 + LoginRuntime.LoginCurrentTime = Date.now(); return true; } if (LoginRuntime.LoginCurrentRate <= RateLimit) { - LoginRuntime.LoginCurrentRate++; return true; } return false;