From 6a3dce523bc58d8e7d55978f15d4cdcafb4fce9b Mon Sep 17 00:00:00 2001 From: atoz03 Date: Thu, 4 Dec 2025 15:02:07 +0800 Subject: [PATCH] chore: format usage stats route --- src/routes/admin/usageStats.js | 24 ++++++++++++++---------- src/routes/admin/utils.js | 4 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/routes/admin/usageStats.js b/src/routes/admin/usageStats.js index 604a6a46..b64fc724 100644 --- a/src/routes/admin/usageStats.js +++ b/src/routes/admin/usageStats.js @@ -371,7 +371,9 @@ router.get('/usage-trend', authenticateAdmin, async (req, res) => { logger.info(` endDate (raw): ${endDate}`) logger.info(` startTime (parsed): ${startTime.toISOString()}`) logger.info(` endTime (parsed): ${endTime.toISOString()}`) - logger.info(` System timezone offset: ${require('../../../config/config').system.timezoneOffset || 8}`) + logger.info( + ` System timezone offset: ${require('../../../config/config').system.timezoneOffset || 8}` + ) } else { // 默认最近24小时 endTime = new Date() @@ -1841,7 +1843,10 @@ router.get('/api-keys/:keyId/usage-records', authenticateAdmin, async (req, res) const startTime = startDate ? new Date(startDate) : null const endTime = endDate ? new Date(endDate) : null - if ((startDate && Number.isNaN(startTime?.getTime())) || (endDate && Number.isNaN(endTime?.getTime()))) { + if ( + (startDate && Number.isNaN(startTime?.getTime())) || + (endDate && Number.isNaN(endTime?.getTime())) + ) { return res.status(400).json({ success: false, error: 'Invalid date range' }) } @@ -2071,14 +2076,13 @@ router.get('/api-keys/:keyId/usage-records', authenticateAdmin, async (req, res) record.costFormatted || costData?.formatted?.total || CostCalculator.formatCost(computedCost), - costBreakdown: - record.costBreakdown || { - input: costData?.costs?.input || 0, - output: costData?.costs?.output || 0, - cacheCreate: costData?.costs?.cacheWrite || 0, - cacheRead: costData?.costs?.cacheRead || 0, - total: costData?.costs?.total || computedCost - }, + costBreakdown: record.costBreakdown || { + input: costData?.costs?.input || 0, + output: costData?.costs?.output || 0, + cacheCreate: costData?.costs?.cacheWrite || 0, + cacheRead: costData?.costs?.cacheRead || 0, + total: costData?.costs?.total || computedCost + }, responseTime: record.responseTime || null }) } diff --git a/src/routes/admin/utils.js b/src/routes/admin/utils.js index 47b68123..49c02015 100644 --- a/src/routes/admin/utils.js +++ b/src/routes/admin/utils.js @@ -33,7 +33,9 @@ function mapExpiryField(updates, accountType, accountId) { if ('expiresAt' in mappedUpdates) { mappedUpdates.subscriptionExpiresAt = mappedUpdates.expiresAt delete mappedUpdates.expiresAt - logger.info(`Mapping expiresAt to subscriptionExpiresAt for ${accountType} account ${accountId}`) + logger.info( + `Mapping expiresAt to subscriptionExpiresAt for ${accountType} account ${accountId}` + ) } return mappedUpdates }