From 029d97236bd9059b3d0c524134aca22a7a44b6e5 Mon Sep 17 00:00:00 2001 From: hex2077 Date: Thu, 4 Dec 2025 18:05:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20=3F=3F=20=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20||=20=E8=BF=90=E7=AE=97=E7=AC=A6=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E6=AD=A3=E7=A1=AE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将逻辑或(||)运算符替换为空值合并(??)运算符,确保当配置值为0时不会被错误地替换为默认值。同时更新了相关日志信息以显示当前设置的maxErrorCount值。 --- src/provider-pool-manager.js | 7 ++++--- src/service-manager.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/provider-pool-manager.js b/src/provider-pool-manager.js index f66292a..1a2ad0a 100644 --- a/src/provider-pool-manager.js +++ b/src/provider-pool-manager.js @@ -21,8 +21,9 @@ export class ProviderPoolManager { this.globalConfig = options.globalConfig || {}; // 存储全局配置 this.providerStatus = {}; // Tracks health and usage for each provider instance this.roundRobinIndex = {}; // Tracks the current index for round-robin selection for each provider type - this.maxErrorCount = options.maxErrorCount || 3; // Default to 3 errors before marking unhealthy - this.healthCheckInterval = options.healthCheckInterval || 10 * 60 * 1000; // Default to 10 minutes + // 使用 ?? 运算符确保 0 也能被正确设置,而不是被 || 替换为默认值 + this.maxErrorCount = options.maxErrorCount ?? 3; // Default to 3 errors before marking unhealthy + this.healthCheckInterval = options.healthCheckInterval ?? 10 * 60 * 1000; // Default to 10 minutes // 日志级别控制 this.logLevel = options.logLevel || 'info'; // 'debug', 'info', 'warn', 'error' @@ -87,7 +88,7 @@ export class ProviderPoolManager { }); }); } - this._log('info', 'Initialized provider statuses: ok'); + this._log('info', `Initialized provider statuses: ok (maxErrorCount: ${this.maxErrorCount})`); } /** diff --git a/src/service-manager.js b/src/service-manager.js index de8dae0..123cefc 100644 --- a/src/service-manager.js +++ b/src/service-manager.js @@ -14,7 +14,7 @@ export async function initApiService(config) { if (config.providerPools && Object.keys(config.providerPools).length > 0) { providerPoolManager = new ProviderPoolManager(config.providerPools, { globalConfig: config, - maxErrorCount: config.MAX_ERROR_COUNT || 3 + maxErrorCount: config.MAX_ERROR_COUNT ?? 3 }); console.log('[Initialization] ProviderPoolManager initialized with configured pools.'); // 健康检查将在服务器完全启动后执行