mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: simplify download api
This commit is contained in:
19
packages/lib/client-only/download-file.ts
Normal file
19
packages/lib/client-only/download-file.ts
Normal file
@ -0,0 +1,19 @@
|
||||
export type DownloadFileOptions = {
|
||||
filename: string;
|
||||
data: Blob;
|
||||
};
|
||||
|
||||
export const downloadFile = ({ filename, data }: DownloadFileOptions) => {
|
||||
if (typeof window === 'undefined') {
|
||||
throw new Error('downloadFile can only be called in browser environments');
|
||||
}
|
||||
|
||||
const link = window.document.createElement('a');
|
||||
|
||||
link.href = window.URL.createObjectURL(data);
|
||||
link.download = filename;
|
||||
|
||||
link.click();
|
||||
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
};
|
||||
Reference in New Issue
Block a user