mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch '98-fix-download-document' into 'master'
Fix: [document download] better memory management and introduce delay See merge request Chill-Projet/chill-bundles!539
This commit is contained in:
commit
5d21612c2e
@ -18,22 +18,20 @@ interface DownloadButtonConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface DownloadButtonState {
|
interface DownloadButtonState {
|
||||||
content: null|string
|
is_ready: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<DownloadButtonConfig>();
|
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> {
|
async function download_and_open(event: Event): Promise<void> {
|
||||||
const button = event.target as HTMLAnchorElement;
|
const button = event.target as HTMLAnchorElement;
|
||||||
|
|
||||||
if (null === state.content) {
|
if (!state.is_ready) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const urlInfo = build_download_info_link(props.storedObject.filename);
|
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));
|
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.href = window.URL.createObjectURL(raw);
|
||||||
button.type = props.storedObject.type;
|
button.type = props.storedObject.type;
|
||||||
@ -44,8 +42,13 @@ async function download_and_open(event: Event): Promise<void> {
|
|||||||
if (null !== ext) {
|
if (null !== ext) {
|
||||||
button.download = button.download + '.' + 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>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user