From 50539ed4851b283b0c629f61e415c4142291c5cc Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 21 Aug 2024 14:32:14 +0200 Subject: [PATCH] Delete files from OPFS when user closes the ReceiveFileDialog --- public/scripts/ui.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 8bc12d8..989b1d7 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -1306,8 +1306,6 @@ class ReceiveFileDialog extends ReceiveDialog { Events.fire('notify-user', downloadSuccessfulTranslation); this.downloadSuccessful = true; - - this.hide(); }; } @@ -1335,8 +1333,6 @@ class ReceiveFileDialog extends ReceiveDialog { Events.fire('notify-user', downloadSuccessfulTranslation); this.downloadSuccessful = true; - - this.hide(); }; } @@ -1400,6 +1396,7 @@ class ReceiveFileDialog extends ReceiveDialog { this.$downloadBtn.removeAttribute('disabled'); this.$downloadBtn.removeAttribute('hidden'); + // Todo: complete rewrite of the download button logic and file zipping let {sendAsZip, zipObjectUrl, zipName} = await this._processDataAsZip(); // If single file or zipping failed or file size exceeds memory -> download files individually -> else download zip @@ -1438,6 +1435,16 @@ class ReceiveFileDialog extends ReceiveDialog { this.$previewBox.innerHTML = ''; } + async _deleteFilesFromDisk(files) { + for(const file of files) { + if (!file.id) { + continue; + } + let fileId = await SWFileDigester.deleteFileById(file.id) + Logger.log(`File with id: ${fileId} successfully deleted.`) + } + } + hide() { super.hide(); @@ -1445,6 +1452,10 @@ class ReceiveFileDialog extends ReceiveDialog { this._tidyUpButtons(); this._tidyUpPreviewBox(); + let oldFiles = this._data.files; + this._deleteFilesFromDisk(oldFiles) + .then(() => Logger.log("Deletion of old files finished.")) + this._busy = false; await this._processFiles();