Remove documents from memory after download

Implemented functionality to remove documents from browser memory 45 seconds after they are converted or downloaded. This ensures that clicking the download button again re-downloads the document. The reset state function was added to both ConvertButton.vue and DownloadButton.vue components.
This commit is contained in:
Julien Fastré 2024-09-11 13:22:49 +02:00
parent 2bef3c3878
commit 8b1b255050
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,7 @@
kind: Feature
body: When a document is converted or downloaded in the browser, this document is
removed from the browser memory after 45s. Future click on the button re-download
the document.
time: 2024-09-11T13:21:34.444838795+02:00
custom:
Issue: "306"

View File

@ -1,5 +1,5 @@
<template> <template>
<a :class="props.classes" @click="download_and_open($event)"> <a :class="props.classes" @click="download_and_open($event)" ref="btn">
<i class="fa fa-file-pdf-o"></i> <i class="fa fa-file-pdf-o"></i>
Télécharger en pdf Télécharger en pdf
</a> </a>
@ -9,7 +9,7 @@
import {build_convert_link, download_and_decrypt_doc, download_doc} from "./helpers"; import {build_convert_link, download_and_decrypt_doc, download_doc} from "./helpers";
import mime from "mime"; import mime from "mime";
import {reactive} from "vue"; import {reactive, ref} from "vue";
import {StoredObject, StoredObjectCreated} from "../../types"; import {StoredObject, StoredObjectCreated} from "../../types";
interface ConvertButtonConfig { interface ConvertButtonConfig {
@ -24,6 +24,7 @@ interface DownloadButtonState {
const props = defineProps<ConvertButtonConfig>(); const props = defineProps<ConvertButtonConfig>();
const state: DownloadButtonState = reactive({content: null}); const state: DownloadButtonState = reactive({content: null});
const btn = ref<HTMLAnchorElement | null>(null);
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;
@ -41,6 +42,14 @@ async function download_and_open(event: Event): Promise<void> {
} }
button.click(); button.click();
const reset_pending = setTimeout(reset_state, 45000);
}
function reset_state(): void {
state.content = null;
btn.value?.removeAttribute('download');
btn.value?.removeAttribute('href');
btn.value?.removeAttribute('type');
} }
</script> </script>

View File

@ -86,6 +86,14 @@ async function download_and_open(event: Event): Promise<void> {
console.log('openbutton after next tick', open_button.value); console.log('openbutton after next tick', open_button.value);
open_button.value?.click(); open_button.value?.click();
console.log('open button should have been clicked'); console.log('open button should have been clicked');
const timer = setTimeout(reset_state, 45000);
}
function reset_state(): void {
state.href_url = '#';
state.is_ready = false;
state.is_running = false;
} }
</script> </script>