diff --git a/svelte/src/file_viewer/Downloader.svelte b/svelte/src/file_viewer/Downloader.svelte index 566d02d..051b327 100644 --- a/svelte/src/file_viewer/Downloader.svelte +++ b/svelte/src/file_viewer/Downloader.svelte @@ -4,15 +4,16 @@ import Modal from "../util/Modal.svelte" export let file = { id: "", + name: "", availability: "", download_href: "", } export let list = { id: "", + title: "", download_href: "", } -let download_frame let load_captcha_script = false let download_captcha_window let captcha_type = "" // rate_limit or malware @@ -24,13 +25,13 @@ let error_code = "" let error_message = "" export const download_file = () => { if (!window.viewer_data.captcha_key) { - console.debug("Server doesn't support captcha, starting download") - download_frame.src = file.download_href + console.debug("Server doesn't support captcha, starting download", file.download_href) + download(file.download_href, file.name) return } if (file.availability === "") { - console.debug("File is available, starting download") - download_frame.src = file.download_href + console.debug("File is available, starting download", file.download_href) + download(file.download_href, file.name) return } if (!file.availability.endsWith("_captcha_required")) { @@ -47,7 +48,8 @@ export const download_file = () => { // we trigger the download using the captcha token Google provided us with let captcha_complete_callback = token => { // Download the file using the recaptcha token - download_frame.src = file.download_href + "&recaptcha_response=" + token + console.debug("Captcha validation successful, starting download", file.download_href) + download(file.download_href + "&recaptcha_response=" + token, file.name) download_captcha_window.hide() } @@ -91,9 +93,17 @@ export const download_file = () => { } export const download_list = () => { if (list.id !== "") { - download_frame.src = list.download_href + download(list.download_href, list.title+".zip") } } + +const download = (href, file_name) => { + let a = document.createElement("a") + a.href = href + a.download = file_name + a.click() + a.remove() +} @@ -102,7 +112,6 @@ export const download_list = () => { {/if} - {#if captcha_type === "rate_limit"}

@@ -143,12 +152,6 @@ export const download_list = () => {