fix:webui auth ratelimit
This commit is contained in:
1 parent
ba20a8e346
commit
39a7068b59
2 files changed
+4
-2
No files matched your search
@@ -13,7 +13,7 @@ export const LoginHandler: RequestHandler = async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let config = await WebUIConfig();
|
let config = await WebUIConfig();
|
||||||
if (!DataRuntime.checkLoginRate(config.loginRate)) {
|
if (!await DataRuntime.checkLoginRate(config.loginRate)) {
|
||||||
res.json({
|
res.json({
|
||||||
code: -1,
|
code: -1,
|
||||||
message: 'login rate limit'
|
message: 'login rate limit'
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ let LoginRuntime: LoginRuntimeType = {
|
|||||||
}
|
}
|
||||||
export const DataRuntime = {
|
export const DataRuntime = {
|
||||||
checkLoginRate: async function (RateLimit: number): Promise<boolean> {
|
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) {
|
if (Date.now() - LoginRuntime.LoginCurrentTime > 1000 * 60) {
|
||||||
LoginRuntime.LoginCurrentRate = 0;//超出时间重置限速
|
LoginRuntime.LoginCurrentRate = 0;//超出时间重置限速
|
||||||
|
LoginRuntime.LoginCurrentTime = Date.now();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (LoginRuntime.LoginCurrentRate <= RateLimit) {
|
if (LoginRuntime.LoginCurrentRate <= RateLimit) {
|
||||||
LoginRuntime.LoginCurrentRate++;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user