fix:webui auth ratelimit

This commit is contained in:
手瓜一十雪 2024-05-07 22:04:21 +08:00
parent 09eaa3116a
commit 24658edc45
2 changed files with 4 additions and 2 deletions

View File

@ -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'

View File

@ -22,12 +22,14 @@ let LoginRuntime: LoginRuntimeType = {
}
export const DataRuntime = {
checkLoginRate: async function (RateLimit: number): Promise<boolean> {
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;