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 {