From bbd3d2a83fba5a3f3e04f6a3b5e45d2b9bd4b940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 19 May 2023 11:34:25 +0200 Subject: [PATCH] Fix: [document download] better memory management and introduce delay before opening Related to https://gitlab.com/Chill-Projet/chill-bundles/-/issues/98 --- .../vuejs/StoredObjectButton/DownloadButton.vue | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue index f05d1e91c..98645873b 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/StoredObjectButton/DownloadButton.vue @@ -18,22 +18,20 @@ interface DownloadButtonConfig { } interface DownloadButtonState { - content: null|string + is_ready: boolean } const props = defineProps(); -const state: DownloadButtonState = reactive({content: null}); +const state: DownloadButtonState = reactive({is_ready: false}); async function download_and_open(event: Event): Promise { const button = event.target as HTMLAnchorElement; - if (null === state.content) { + if (!state.is_ready) { event.preventDefault(); - const urlInfo = build_download_info_link(props.storedObject.filename); const raw = await download_and_decrypt_doc(urlInfo, props.storedObject.keyInfos, new Uint8Array(props.storedObject.iv)); - state.content = window.URL.createObjectURL(raw); button.href = window.URL.createObjectURL(raw); button.type = props.storedObject.type; @@ -44,8 +42,13 @@ async function download_and_open(event: Event): Promise { if (null !== ext) { button.download = button.download + '.' + ext; } - } - button.click(); + state.is_ready = true; + + // for fixing https://gitlab.com/Chill-Projet/chill-bundles/-/issues/98 + window.setTimeout(() => { + button.click() + }, 750); + } }