refactor: extract formatCompactNumber util and add last_used_at to refresh key

- Add formatCompactNumber() for consistent large-number formatting (K/M/B)
- Include last_used_at in OpenAI usage refresh key for better change detection
- Add .gitattributes eol=lf rules for frontend source files
This commit is contained in:
Ethan0x0000
2026-03-16 16:22:51 +08:00
parent fa782e70a4
commit 8640a62319
5 changed files with 75 additions and 1 deletions

View File

@@ -247,6 +247,26 @@ export function formatTokensK(tokens: number): string {
return tokens.toString()
}
/**
* 格式化大数字K/M/B保留 1 位小数)
* @param num 数字
* @param options allowBillions=false 时最高只显示到 M
*/
export function formatCompactNumber(
num: number | null | undefined,
options?: { allowBillions?: boolean }
): string {
if (num === null || num === undefined) return '0'
const abs = Math.abs(num)
const allowBillions = options?.allowBillions !== false
if (allowBillions && abs >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(1)}B`
if (abs >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`
if (abs >= 1_000) return `${(num / 1_000).toFixed(1)}K`
return num.toString()
}
/**
* 格式化倒计时(从现在到目标时间的剩余时间)
* @param targetDate 目标日期字符串或 Date 对象