mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
chore: format usage stats route
This commit is contained in:
@@ -371,7 +371,9 @@ router.get('/usage-trend', authenticateAdmin, async (req, res) => {
|
|||||||
logger.info(` endDate (raw): ${endDate}`)
|
logger.info(` endDate (raw): ${endDate}`)
|
||||||
logger.info(` startTime (parsed): ${startTime.toISOString()}`)
|
logger.info(` startTime (parsed): ${startTime.toISOString()}`)
|
||||||
logger.info(` endTime (parsed): ${endTime.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 {
|
} else {
|
||||||
// 默认最近24小时
|
// 默认最近24小时
|
||||||
endTime = new Date()
|
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 startTime = startDate ? new Date(startDate) : null
|
||||||
const endTime = endDate ? new Date(endDate) : 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' })
|
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 ||
|
record.costFormatted ||
|
||||||
costData?.formatted?.total ||
|
costData?.formatted?.total ||
|
||||||
CostCalculator.formatCost(computedCost),
|
CostCalculator.formatCost(computedCost),
|
||||||
costBreakdown:
|
costBreakdown: record.costBreakdown || {
|
||||||
record.costBreakdown || {
|
input: costData?.costs?.input || 0,
|
||||||
input: costData?.costs?.input || 0,
|
output: costData?.costs?.output || 0,
|
||||||
output: costData?.costs?.output || 0,
|
cacheCreate: costData?.costs?.cacheWrite || 0,
|
||||||
cacheCreate: costData?.costs?.cacheWrite || 0,
|
cacheRead: costData?.costs?.cacheRead || 0,
|
||||||
cacheRead: costData?.costs?.cacheRead || 0,
|
total: costData?.costs?.total || computedCost
|
||||||
total: costData?.costs?.total || computedCost
|
},
|
||||||
},
|
|
||||||
responseTime: record.responseTime || null
|
responseTime: record.responseTime || null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ function mapExpiryField(updates, accountType, accountId) {
|
|||||||
if ('expiresAt' in mappedUpdates) {
|
if ('expiresAt' in mappedUpdates) {
|
||||||
mappedUpdates.subscriptionExpiresAt = mappedUpdates.expiresAt
|
mappedUpdates.subscriptionExpiresAt = mappedUpdates.expiresAt
|
||||||
delete 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
|
return mappedUpdates
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user