diff options
Diffstat (limited to 'subprojects/frontend/src/utils/fileIO.ts')
-rw-r--r-- | subprojects/frontend/src/utils/fileIO.ts | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/subprojects/frontend/src/utils/fileIO.ts b/subprojects/frontend/src/utils/fileIO.ts index abcc43eb..4f376882 100644 --- a/subprojects/frontend/src/utils/fileIO.ts +++ b/subprojects/frontend/src/utils/fileIO.ts | |||
@@ -7,28 +7,13 @@ | |||
7 | export async function saveBlob( | 7 | export async function saveBlob( |
8 | blob: Blob, | 8 | blob: Blob, |
9 | name: string, | 9 | name: string, |
10 | mimeType: string, | 10 | options: FilePickerOptions, |
11 | id?: string, | ||
12 | ): Promise<void> { | 11 | ): Promise<void> { |
13 | if ('showSaveFilePicker' in window) { | 12 | if ('showSaveFilePicker' in window) { |
14 | const options: FilePickerOptions = { | 13 | const handle = await window.showSaveFilePicker({ |
14 | ...options, | ||
15 | suggestedName: name, | 15 | suggestedName: name, |
16 | }; | 16 | }); |
17 | if (id !== undefined) { | ||
18 | options.id = id; | ||
19 | } | ||
20 | const extensionIndex = name.lastIndexOf('.'); | ||
21 | if (extensionIndex >= 0) { | ||
22 | options.types = [ | ||
23 | { | ||
24 | description: `${name.substring(extensionIndex + 1)} files`, | ||
25 | accept: { | ||
26 | [mimeType]: [name.substring(extensionIndex)], | ||
27 | }, | ||
28 | }, | ||
29 | ]; | ||
30 | } | ||
31 | const handle = await window.showSaveFilePicker(options); | ||
32 | const writable = await handle.createWritable(); | 17 | const writable = await handle.createWritable(); |
33 | try { | 18 | try { |
34 | await writable.write(blob); | 19 | await writable.write(blob); |
@@ -42,12 +27,9 @@ export async function saveBlob( | |||
42 | try { | 27 | try { |
43 | link.href = url; | 28 | link.href = url; |
44 | link.download = name; | 29 | link.download = name; |
45 | link.style.display = 'none'; | ||
46 | document.body.appendChild(link); | ||
47 | link.click(); | 30 | link.click(); |
48 | } finally { | 31 | } finally { |
49 | window.URL.revokeObjectURL(url); | 32 | window.URL.revokeObjectURL(url); |
50 | document.body.removeChild(link); | ||
51 | } | 33 | } |
52 | } | 34 | } |
53 | 35 | ||