2026-05-02 13:02:57 +08:00

15 lines
482 B
TypeScript

export async function downloadResponse(response: Response, filename: string) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.click();
window.URL.revokeObjectURL(url);
}
export async function downloadCsv(request: () => Promise<Response>, filename: string) {
const response = await request();
await downloadResponse(response, filename);
}