From fcecb75c21a2c4956845b308a58a0facc489cc39 Mon Sep 17 00:00:00 2001 From: KevinLiao Date: Mon, 28 Jul 2025 09:04:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=201.=E4=BF=AE=E6=AD=A3=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9F=A5=E8=AF=A2apikey=E6=97=B6=E5=8C=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202.=E4=BF=AE=E6=AD=A3=E7=94=A8=E6=88=B7apikey?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2,=E5=BD=93=E6=97=A5APIKey=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=98=BE=E7=A4=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/apiStats.js | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/src/routes/apiStats.js b/src/routes/apiStats.js index 6f24819d..d190285b 100644 --- a/src/routes/apiStats.js +++ b/src/routes/apiStats.js @@ -443,8 +443,10 @@ router.post('/api/user-model-stats', async (req, res) => { // 重用管理后台的模型统计逻辑,但只返回该API Key的数据 const client = redis.getClientSafe(); - const today = new Date().toISOString().split('T')[0]; - const currentMonth = `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, '0')}`; + // 使用与管理页面相同的时区处理逻辑 + const tzDate = redis.getDateInTimezone(); + const today = redis.getDateStringInTimezone(); + const currentMonth = `${tzDate.getFullYear()}-${String(tzDate.getMonth() + 1).padStart(2, '0')}`; const pattern = period === 'daily' ? `usage:${keyId}:model:daily:*:${today}` : @@ -489,33 +491,10 @@ router.post('/api/user-model-stats', async (req, res) => { } } - // 如果没有详细的模型数据,尝试从总体usage中生成 - if (modelStats.length === 0 && keyData.usage?.total) { - const usageData = keyData.usage.total; - - if (usageData.allTokens > 0) { - const usage = { - input_tokens: usageData.inputTokens || 0, - output_tokens: usageData.outputTokens || 0, - cache_creation_input_tokens: usageData.cacheCreateTokens || 0, - cache_read_input_tokens: usageData.cacheReadTokens || 0 - }; - - const costData = CostCalculator.calculateCost(usage, 'claude-3-5-sonnet-20241022'); - - modelStats.push({ - model: '总体使用 (历史数据)', - requests: usageData.requests || 0, - inputTokens: usageData.inputTokens || 0, - outputTokens: usageData.outputTokens || 0, - cacheCreateTokens: usageData.cacheCreateTokens || 0, - cacheReadTokens: usageData.cacheReadTokens || 0, - allTokens: usageData.allTokens || 0, - costs: costData.costs, - formatted: costData.formatted, - pricing: costData.pricing - }); - } + // 如果没有详细的模型数据,不显示历史数据以避免混淆 + // 只有在查询特定时间段时返回空数组,表示该时间段确实没有数据 + if (modelStats.length === 0) { + logger.info(`📊 No model stats found for key ${keyId} in period ${period}`); } // 按总token数降序排列 From 7d27cf8e13c3dca09ae88707f55e3cd26bcff55b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 28 Jul 2025 01:07:01 +0000 Subject: [PATCH 2/2] chore: sync VERSION file with release v1.1.39 [skip ci] --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 54eae6b4..1b507d18 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.38 +1.1.39