mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
fix(export): harden downloads and CSV encoding
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
export type DownloadBlobOptions = {
|
||||
filename: string;
|
||||
blob: Blob;
|
||||
revokeDelayMs?: number;
|
||||
};
|
||||
|
||||
export function downloadBlob({ filename, blob, revokeDelayMs = 1000 }: DownloadBlobOptions) {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
link.rel = 'noopener';
|
||||
link.style.display = 'none';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
window.setTimeout(() => {
|
||||
window.URL.revokeObjectURL(url);
|
||||
link.remove();
|
||||
}, revokeDelayMs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user