feat(worker): Geschiedenis screen with session list and CSV export
This commit is contained in:
23
apps/worker/src/lib/export.ts
Normal file
23
apps/worker/src/lib/export.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { API_URL } from './api';
|
||||
import { getToken } from './auth-storage';
|
||||
|
||||
/**
|
||||
* Authenticated CSV download. A plain `<a href>` cannot carry the bearer token,
|
||||
* so we fetch the blob ourselves and trigger a download via an object URL.
|
||||
*/
|
||||
export async function downloadExport(): Promise<void> {
|
||||
const token = getToken();
|
||||
const res = await fetch(`${API_URL}/api/export`, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
});
|
||||
if (!res.ok) throw new Error('Kan de export niet openen');
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'insole-production-report.csv';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
Reference in New Issue
Block a user