From 9471e63857f281e2eb87c4a6fa1ee1fad1950b4d 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: Mon, 6 May 2024 22:24:27 +0800 Subject: [PATCH] feat: webui login limit --- src/webui/src/api/{Auth.ts => QQLogin.ts} | 0 src/webui/src/helper/Data.ts | 17 +++++++++++++++++ src/webui/src/helper/{Auth.ts => SignToken.ts} | 0 src/webui/src/{common => helper}/config.ts | 0 static/{authlogin.html => QQLogin.html} | 0 static/index.html | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) rename src/webui/src/api/{Auth.ts => QQLogin.ts} (100%) create mode 100644 src/webui/src/helper/Data.ts rename src/webui/src/helper/{Auth.ts => SignToken.ts} (100%) rename src/webui/src/{common => helper}/config.ts (100%) rename static/{authlogin.html => QQLogin.html} (100%) diff --git a/src/webui/src/api/Auth.ts b/src/webui/src/api/QQLogin.ts similarity index 100% rename from src/webui/src/api/Auth.ts rename to src/webui/src/api/QQLogin.ts diff --git a/src/webui/src/helper/Data.ts b/src/webui/src/helper/Data.ts new file mode 100644 index 00000000..8d775556 --- /dev/null +++ b/src/webui/src/helper/Data.ts @@ -0,0 +1,17 @@ +let LoginRuntime = { + LoginCurrentTime: Date.now(), + LoginCurrentRate: 0 +} +export const Data = { + checkLoginRate: async function (RateLimit: number): Promise { + if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) { + LoginRuntime.LoginCurrentRate = 0;//超出时间重置限速 + return true; + } + if (LoginRuntime.LoginCurrentRate <= RateLimit) { + LoginRuntime.LoginCurrentRate++; + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/webui/src/helper/Auth.ts b/src/webui/src/helper/SignToken.ts similarity index 100% rename from src/webui/src/helper/Auth.ts rename to src/webui/src/helper/SignToken.ts diff --git a/src/webui/src/common/config.ts b/src/webui/src/helper/config.ts similarity index 100% rename from src/webui/src/common/config.ts rename to src/webui/src/helper/config.ts diff --git a/static/authlogin.html b/static/QQLogin.html similarity index 100% rename from static/authlogin.html rename to static/QQLogin.html diff --git a/static/index.html b/static/index.html index d01f779f..fc2d1b22 100644 --- a/static/index.html +++ b/static/index.html @@ -3,7 +3,7 @@ - Document + WebUi - Index