From 375d70ee1f7a12669f96fc72b696f6c1dc30717c Mon Sep 17 00:00:00 2001 From: KevinLiao Date: Sun, 27 Jul 2025 12:03:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20APIKeys=20=E5=88=97=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=91=A8=E6=9C=9F=E9=80=89=E9=A1=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BB=8A=E6=97=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/admin.js | 12 ++++++++++-- web/admin/index.html | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/routes/admin.js b/src/routes/admin.js index 0ff4ca62..18f7c9d0 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -28,7 +28,11 @@ router.get('/api-keys', authenticateAdmin, async (req, res) => { const now = new Date(); let searchPatterns = []; - if (timeRange === '7days') { + if (timeRange === 'today') { + // 今日 + const dateStr = now.toISOString().split('T')[0]; + searchPatterns.push(`usage:daily:*:${dateStr}`); + } else if (timeRange === '7days') { // 最近7天 for (let i = 0; i < 7; i++) { const date = new Date(now); @@ -145,7 +149,9 @@ router.get('/api-keys', authenticateAdmin, async (req, res) => { // 计算指定时间范围的费用 let totalCost = 0; - const modelKeys = timeRange === '7days' + const modelKeys = timeRange === 'today' + ? await client.keys(`usage:${apiKey.id}:model:daily:*:${now.toISOString().split('T')[0]}`) + : timeRange === '7days' ? await client.keys(`usage:${apiKey.id}:model:daily:*:*`) : await client.keys(`usage:${apiKey.id}:model:monthly:*:${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`); @@ -161,6 +167,8 @@ router.get('/api-keys', authenticateAdmin, async (req, res) => { const daysDiff = Math.floor((now - keyDate) / (1000 * 60 * 60 * 24)); if (daysDiff > 6) continue; } + } else if (timeRange === 'today') { + // today选项已经在查询时过滤了,不需要额外处理 } const modelMatch = key.match(/usage:.+:model:(?:daily|monthly):(.+):\d{4}-\d{2}(?:-\d{2})?$/); diff --git a/web/admin/index.html b/web/admin/index.html index 99e076bf..2bbae079 100644 --- a/web/admin/index.html +++ b/web/admin/index.html @@ -543,11 +543,12 @@