mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
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:
parent
fbd555e89a
commit
bbd3d2a83f
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user