mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
Merge branch 'dev'
This commit is contained in:
@@ -1190,17 +1190,17 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
|
|||||||
} else if (period === 'monthly') {
|
} else if (period === 'monthly') {
|
||||||
pattern = `usage:model:monthly:*:${currentMonth}`;
|
pattern = `usage:model:monthly:*:${currentMonth}`;
|
||||||
} else {
|
} else {
|
||||||
// 全部时间,先尝试从Redis获取所有历史模型统计数据
|
// 全部时间,先尝试从Redis获取所有历史模型统计数据(只使用monthly数据避免重复计算)
|
||||||
const allModelKeys = await client.keys('usage:model:*:*');
|
const allModelKeys = await client.keys('usage:model:monthly:*:*');
|
||||||
logger.info(`💰 Total period calculation: found ${allModelKeys.length} model keys`);
|
logger.info(`💰 Total period calculation: found ${allModelKeys.length} monthly model keys`);
|
||||||
|
|
||||||
if (allModelKeys.length > 0) {
|
if (allModelKeys.length > 0) {
|
||||||
// 如果有详细的模型统计数据,使用模型级别的计算
|
// 如果有详细的模型统计数据,使用模型级别的计算
|
||||||
const modelUsageMap = new Map();
|
const modelUsageMap = new Map();
|
||||||
|
|
||||||
for (const key of allModelKeys) {
|
for (const key of allModelKeys) {
|
||||||
// 解析模型名称
|
// 解析模型名称(只处理monthly数据)
|
||||||
let modelMatch = key.match(/usage:model:(?:daily|monthly):(.+):\d{4}-\d{2}(?:-\d{2})?$/);
|
let modelMatch = key.match(/usage:model:monthly:(.+):(\d{4}-\d{2})$/);
|
||||||
if (!modelMatch) continue;
|
if (!modelMatch) continue;
|
||||||
|
|
||||||
const model = modelMatch[1];
|
const model = modelMatch[1];
|
||||||
|
|||||||
Reference in New Issue
Block a user