fix: usage stats issue

This commit is contained in:
Feng Yue
2025-08-14 16:16:27 +08:00
parent 283583d289
commit 6b4ce99237
2 changed files with 15 additions and 5 deletions

View File

@@ -294,8 +294,8 @@ router.get('/usage-stats', authenticateUser, async (req, res) => {
try { try {
const { period = 'week', model } = req.query const { period = 'week', model } = req.query
// 获取用户的API Keys // 获取用户的API Keys (including deleted ones for complete usage stats)
const userApiKeys = await apiKeyService.getUserApiKeys(req.user.id) const userApiKeys = await apiKeyService.getUserApiKeys(req.user.id, true)
const apiKeyIds = userApiKeys.map((key) => key.id) const apiKeyIds = userApiKeys.map((key) => key.id)
if (apiKeyIds.length === 0) { if (apiKeyIds.length === 0) {

View File

@@ -298,10 +298,20 @@
<span <span
:class="[ :class="[
'inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium', 'inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
apiKey.isActive ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' apiKey.isDeleted === 'true' || apiKey.deletedAt
? 'bg-gray-100 text-gray-800'
: apiKey.isActive
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800'
]" ]"
> >
{{ apiKey.isActive ? 'Active' : 'Disabled' }} {{
apiKey.isDeleted === 'true' || apiKey.deletedAt
? 'Deleted'
: apiKey.isActive
? 'Active'
: 'Disabled'
}}
</span> </span>
</td> </td>
</tr> </tr>
@@ -364,7 +374,7 @@ const loadUsageStats = async () => {
try { try {
const [stats, apiKeys] = await Promise.all([ const [stats, apiKeys] = await Promise.all([
userStore.getUserUsageStats({ period: selectedPeriod.value }), userStore.getUserUsageStats({ period: selectedPeriod.value }),
userStore.getUserApiKeys() userStore.getUserApiKeys(true) // Include deleted keys
]) ])
usageStats.value = stats usageStats.value = stats