fix 'unusual query volume' check

This commit is contained in:
被遗忘的记忆
2024-10-29 23:33:46 +08:00
committed by GitHub
parent d4d43e1964
commit 181cc5203b
+7 -9
View File
@@ -529,23 +529,18 @@ class YouProvider {
} }
checkAndSwitchMode() { checkAndSwitchMode() {
// 如果当前模式不可用,或者达到轮换阈值 // 如果当前模式不可用
if (!this.modeStatus[this.currentMode] || (this.rotationEnabled && this.switchCounter >= this.switchThreshold)) { if (!this.modeStatus[this.currentMode]) {
console.log(`当前模式 ${this.currentMode} 已达到请求次数阈值`);
const availableModes = Object.keys(this.modeStatus).filter(mode => this.modeStatus[mode]); const availableModes = Object.keys(this.modeStatus).filter(mode => this.modeStatus[mode]);
if (availableModes.length === 0) { if (availableModes.length === 0) {
throw new Error("两种模式达到请求上限。"); console.log("两种模式达到请求上限。");
} else if (availableModes.length === 1) { } else if (availableModes.length === 1) {
console.log(`当前模式 ${this.currentMode} 已达到请求次数阈值`);
this.currentMode = availableModes[0]; this.currentMode = availableModes[0];
this.rotationEnabled = false; this.rotationEnabled = false;
} else {
this.switchMode();
} }
this.switchCounter = 0;
this.requestsInCurrentMode = 0;
this.switchThreshold = this.getRandomSwitchThreshold();
} }
} }
@@ -574,6 +569,9 @@ class YouProvider {
this.switchCounter++; this.switchCounter++;
this.requestsInCurrentMode++; this.requestsInCurrentMode++;
console.log(`当前模式: ${this.currentMode}, 本模式下的请求次数: ${this.requestsInCurrentMode}, 距离下次切换还有 ${this.switchThreshold - this.switchCounter} 次请求`); console.log(`当前模式: ${this.currentMode}, 本模式下的请求次数: ${this.requestsInCurrentMode}, 距离下次切换还有 ${this.switchThreshold - this.switchCounter} 次请求`);
if (this.switchCounter >= this.switchThreshold) {
this.switchMode();
}
} }
// 根据轮换状态决定是否使用自定义模式 // 根据轮换状态决定是否使用自定义模式