mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
feat: APIKeys 列表,统计周期选项增加今日。
This commit is contained in:
@@ -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})?$/);
|
||||
|
||||
@@ -543,11 +543,12 @@
|
||||
<select
|
||||
v-model="apiKeyStatsTimeRange"
|
||||
@change="loadApiKeys()"
|
||||
class="form-select px-4 py-2 bg-white border border-gray-200 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
class="form-input px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="all">全部时间</option>
|
||||
<option value="today">今日</option>
|
||||
<option value="7days">最近7天</option>
|
||||
<option value="monthly">本月</option>
|
||||
<option value="all">全部时间</option>
|
||||
</select>
|
||||
<button
|
||||
@click.stop="openCreateApiKeyModal"
|
||||
|
||||
Reference in New Issue
Block a user