implement backup export

This commit is contained in:
marlon-erler
2026-08-30 00:15:30 +02:00
parent 42110585f6
commit 9caad50b18
4 changed files with 27 additions and 5 deletions
+4 -2
View File
@@ -139,7 +139,7 @@ export default class FileTransferModel {
readonly generateBackup = async (
directoryPaths: IteratorObject<string[]>,
passphrase: string,
): Promise<string> => {
): Promise<Blob> => {
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 => {
+1 -1
View File
@@ -750,7 +750,7 @@ function ExportModal(
</button>
<button
class="primary flex"
on:click={fileTransferViewModel}
on:click={fileTransferViewModel.downloadFile}
toggle:disabled={
fileTransferViewModel.cannotExport
}
@@ -120,6 +120,16 @@ export default class FileTransferViewModel extends Context {
this.transferKey.value = transferData.key;
};
downloadFile = async (): Promise<void> => {
const date = new Date().toISOString().split("T")[0];
const backup: Blob = 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
showDirectionSelectionModal = (): void => {
this.coreViewModel.context = this;