add autodownload

This commit is contained in:
Ruben Fiszel
2023-05-12 00:22:40 +02:00
parent 7c50565160
commit 4cb3ec5fd3
@@ -77,7 +77,22 @@
} else if (keys.length == 1 && keys[0] == 'error') {
return 'error'
} else if (keys.length === 2 && keys.includes('file') && keys.includes('filename')) {
return 'filename'
return 'file'
} else if (
keys.length === 3 &&
keys.includes('file') &&
keys.includes('filename') &&
keys.includes('autodownload')
) {
if (result.autodownload) {
const a = document.createElement('a')
a.href = 'data:application/octet-stream;base64,' + result.file
a.download = result.filename
a.click()
console.log('autodownload', result.file, result.filename)
}
return 'file'
} else if (
keys.length == 3 &&
keys.includes('resume') &&
@@ -192,16 +207,11 @@
</div>
{:else if !forceJson && resultKind == 'file'}
<div
><a download="windmill.file" href="data:application/octet-stream;base64,{result.file}"
>Download</a
><a
download={result.filename ?? 'windmill.file'}
href="data:application/octet-stream;base64,{result.file}">Download</a
>
</div>
{:else if !forceJson && resultKind === 'filename'}
<div>
<a download={result.filename} href="data:application/octet-stream;base64,{result.file}">
Download
</a>
</div>
{:else if !forceJson && resultKind == 'error'}<div>
<span class="text-red-500 font-semibold text-sm whitespace-pre-wrap"
>{#if result.error.name || result.error.message}{result.error.name}: {result.error