diff --git a/src/routes/apiStats.js b/src/routes/apiStats.js index e496b9ab..d144162e 100644 --- a/src/routes/apiStats.js +++ b/src/routes/apiStats.js @@ -97,7 +97,6 @@ router.post('/api/user-stats', async (req, res) => { try { const client = redis.getClientSafe(); - const currentMonth = `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, '0')}`; // 获取所有月度模型统计(与model-stats接口相同的逻辑) const allModelKeys = await client.keys(`usage:${fullKeyData.id}:model:monthly:*:*`); diff --git a/src/routes/web.js b/src/routes/web.js index eac99038..7aacae26 100644 --- a/src/routes/web.js +++ b/src/routes/web.js @@ -6,8 +6,6 @@ const fs = require('fs'); const redis = require('../models/redis'); const logger = require('../utils/logger'); const config = require('../../config/config'); -const apiKeyService = require('../services/apiKeyService'); -const CostCalculator = require('../utils/costCalculator'); const router = express.Router(); diff --git a/src/services/apiKeyService.js b/src/services/apiKeyService.js index ae78cd99..f7a1797b 100644 --- a/src/services/apiKeyService.js +++ b/src/services/apiKeyService.js @@ -147,6 +147,9 @@ class ApiKeyService { keyData: { id: keyData.id, name: keyData.name, + description: keyData.description, + createdAt: keyData.createdAt, + expiresAt: keyData.expiresAt, claudeAccountId: keyData.claudeAccountId, geminiAccountId: keyData.geminiAccountId, permissions: keyData.permissions || 'all', diff --git a/web/apiStats/app.js b/web/apiStats/app.js index 134cd8bb..b61de143 100644 --- a/web/apiStats/app.js +++ b/web/apiStats/app.js @@ -226,6 +226,34 @@ const app = createApp({ } }, + // 📅 格式化过期日期 + formatExpireDate(dateString) { + if (!dateString) return ''; + const date = new Date(dateString); + return date.toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit' + }); + }, + + // 🔍 检查 API Key 是否已过期 + isApiKeyExpired(expiresAt) { + if (!expiresAt) return false; + return new Date(expiresAt) < new Date(); + }, + + // ⏰ 检查 API Key 是否即将过期(7天内) + isApiKeyExpiringSoon(expiresAt) { + if (!expiresAt) return false; + const expireDate = new Date(expiresAt); + const now = new Date(); + const daysUntilExpire = (expireDate - now) / (1000 * 60 * 60 * 24); + return daysUntilExpire > 0 && daysUntilExpire <= 7; + }, + // 🔢 格式化数字 formatNumber(num) { if (typeof num !== 'number') { diff --git a/web/apiStats/index.html b/web/apiStats/index.html index a185f38d..c238effc 100644 --- a/web/apiStats/index.html +++ b/web/apiStats/index.html @@ -169,9 +169,25 @@ 创建时间 {{ formatDate(statsData.createdAt) }} -
+ + 此 API Key 不能访问以上列出的模型 +
++ + 此 API Key 只能被以上列出的客户端使用 +