From 9caad50b182be4d115c2907ccd89872afa73e1df Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Sun, 30 Aug 2026 00:15:30 +0200 Subject: [PATCH] implement backup export --- dist/index.js | 14 ++++++++++++-- src/Model/Global/fileTransferModel.ts | 6 ++++-- src/View/Modals/dataTransferModal.tsx | 2 +- src/ViewModel/Global/fileTransferViewModel.ts | 10 ++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index ed55a800..167b3a85 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1814,6 +1814,14 @@ this.transferChannel.value = transferData.channel; this.transferKey.value = transferData.key; }; + this.downloadFile = async () => { + const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0]; + const backup = await this.coreViewModel.fileTransferModel.generateBackup(this.selectedPaths.value.values(), this.exportKey.value); + const anchor = document.createElement("a"); + anchor.href = window.URL.createObjectURL(backup); + anchor.download = `comms-${date}.bak`; + anchor.click(); + }; // view this.showDirectionSelectionModal = () => { this.coreViewModel.context = this; @@ -7024,7 +7032,7 @@ "button", { class: "primary flex", - "on:click": fileTransferViewModel2, + "on:click": fileTransferViewModel2.downloadFile, "toggle:disabled": fileTransferViewModel2.cannotExport }, coreViewModel2.translations.dataTransferModal.downloadFileButton, @@ -7399,7 +7407,9 @@ }); } const rawBackup = stringify(files); - return await encryptString(rawBackup, passphrase); + const encrypted = await encryptString(rawBackup, passphrase); + const blob = new Blob([encrypted], { type: "text/plain" }); + return blob; }; this.prepareFileForSending = (filePath) => { if (this.transferData == void 0) return; diff --git a/src/Model/Global/fileTransferModel.ts b/src/Model/Global/fileTransferModel.ts index f1f6ad3a..68d92918 100644 --- a/src/Model/Global/fileTransferModel.ts +++ b/src/Model/Global/fileTransferModel.ts @@ -139,7 +139,7 @@ export default class FileTransferModel { readonly generateBackup = async ( directoryPaths: IteratorObject, passphrase: string, - ): Promise => { + ): Promise => { const files: string[] = []; for (const directoryPath of directoryPaths) { this.storageModel.recurse(directoryPath, (filePath: string[]) => { @@ -149,7 +149,9 @@ export default class FileTransferModel { }); } const rawBackup = stringify(files); - return await encryptString(rawBackup, passphrase); + const encrypted = await encryptString(rawBackup, passphrase); + const blob = new Blob([encrypted], {type: "text/plain"}); + return blob; }; readonly prepareFileForSending = (filePath: string[]): string => { diff --git a/src/View/Modals/dataTransferModal.tsx b/src/View/Modals/dataTransferModal.tsx index c4a9e9b6..286abc8e 100644 --- a/src/View/Modals/dataTransferModal.tsx +++ b/src/View/Modals/dataTransferModal.tsx @@ -750,7 +750,7 @@ function ExportModal(