mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-28 00:07:33 +00:00
fix(usage): add UTF-8 BOM to CSV export
This commit is contained in:
@@ -677,7 +677,7 @@ const exportToCSV = async () => {
|
|||||||
headers.map(escapeCSVValue).join(','),
|
headers.map(escapeCSVValue).join(','),
|
||||||
...rows.map((row) => row.join(',')),
|
...rows.map((row) => row.join(',')),
|
||||||
].join('\n')
|
].join('\n')
|
||||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
|
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' })
|
||||||
const url = window.URL.createObjectURL(blob)
|
const url = window.URL.createObjectURL(blob)
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.href = url
|
link.href = url
|
||||||
|
|||||||
@@ -237,6 +237,11 @@ describe('user UsageView', () => {
|
|||||||
}))
|
}))
|
||||||
expect(clickSpy).toHaveBeenCalled()
|
expect(clickSpy).toHaveBeenCalled()
|
||||||
expect(showSuccess).toHaveBeenCalled()
|
expect(showSuccess).toHaveBeenCalled()
|
||||||
|
expect(csvContent.startsWith('\uFEFF')).toBe(true)
|
||||||
|
expect(csvContent.slice(1)).toBe([
|
||||||
|
'Time,API Key Name,Model,Reasoning Effort,Inbound Endpoint,IP Address,Type,Billing Mode,Input Tokens,Output Tokens,Cache Read Tokens,Cache Creation Tokens,Rate Multiplier,Billed Cost,Original Cost,First Token (ms),Duration (ms)',
|
||||||
|
'2026-03-08T00:00:00Z,demo-key,gpt-5.4,"\'-",,203.0.113.10,Sync,Token,4057,101,278272,4,1,0.09288300,0.09288300,12,345',
|
||||||
|
].join('\n'))
|
||||||
expect(csvContent).toContain('IP Address')
|
expect(csvContent).toContain('IP Address')
|
||||||
expect(csvContent).toContain('203.0.113.10')
|
expect(csvContent).toContain('203.0.113.10')
|
||||||
expect(csvContent).toContain('Billed Cost')
|
expect(csvContent).toContain('Billed Cost')
|
||||||
|
|||||||
Reference in New Issue
Block a user