From d49cc0cec83138f164909c5dfb8d0acf23841cdd Mon Sep 17 00:00:00 2001 From: shaw Date: Mon, 8 Dec 2025 09:45:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dapi-keys=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=AA=97=E5=8F=A3=E8=B4=B9=E7=8E=87=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/admin/apiKeys.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/routes/admin/apiKeys.js b/src/routes/admin/apiKeys.js index 9a22cb50..e2ee3c88 100644 --- a/src/routes/admin/apiKeys.js +++ b/src/routes/admin/apiKeys.js @@ -1047,7 +1047,10 @@ async function calculateKeyStats(keyId, timeRange, startDate, endDate) { // 获取 API Key 配置信息以判断是否需要窗口数据 const apiKey = await redis.getApiKey(keyId) - if (apiKey && apiKey.rateLimitWindow > 0) { + // 显式转换为整数,与 apiStats.js 保持一致,避免字符串比较问题 + const rateLimitWindow = parseInt(apiKey?.rateLimitWindow) || 0 + + if (rateLimitWindow > 0) { const costCountKey = `rate_limit:cost:${keyId}` const windowStartKey = `rate_limit:window_start:${keyId}` @@ -1058,7 +1061,7 @@ async function calculateKeyStats(keyId, timeRange, startDate, endDate) { if (windowStart) { const now = Date.now() windowStartTime = parseInt(windowStart) - const windowDuration = apiKey.rateLimitWindow * 60 * 1000 // 转换为毫秒 + const windowDuration = rateLimitWindow * 60 * 1000 // 转换为毫秒 windowEndTime = windowStartTime + windowDuration // 如果窗口还有效 @@ -1072,7 +1075,7 @@ async function calculateKeyStats(keyId, timeRange, startDate, endDate) { } } } catch (error) { - logger.debug(`获取实时限制数据失败 (key: ${keyId}):`, error.message) + logger.warn(`⚠️ 获取实时限制数据失败 (key: ${keyId}):`, error.message) } return {