Fix: [document download] better memory management and introduce delay

before opening

Related to https://gitlab.com/Chill-Projet/chill-bundles/-/issues/98
This commit is contained in:
Julien Fastré 2023-05-19 11:34:25 +02:00
parent fbd555e89a
commit bbd3d2a83f
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -18,22 +18,20 @@ interface DownloadButtonConfig {
}
interface DownloadButtonState {
content: null|string
is_ready: boolean
}
const props = defineProps<DownloadButtonConfig>();
const state: DownloadButtonState = reactive({content: null});
const state: DownloadButtonState = reactive({is_ready: false});
async function download_and_open(event: Event): Promise<void> {
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<void> {
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);
}
}
</script>