mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 13:01:14 +00:00
fix:webui auth ratelimit
This commit is contained in:
parent
09eaa3116a
commit
24658edc45
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user