From b888e68c5aa9853c1fa7d046c928920b22cc4337 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Tue, 21 Jul 2020 18:02:33 +0200 Subject: [PATCH] fix: bundle files together when exporting a decrypted backup --- .../directives/views/accountMenu.js | 1 + .../javascripts/services/archiveManager.js | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/directives/views/accountMenu.js b/app/assets/javascripts/directives/views/accountMenu.js index efc8c191f..a14389ed6 100644 --- a/app/assets/javascripts/directives/views/accountMenu.js +++ b/app/assets/javascripts/directives/views/accountMenu.js @@ -445,6 +445,7 @@ class AccountMenuCtrl extends PureCtrl { async downloadDataArchive() { this.archiveManager.downloadBackup(this.state.mutable.backupEncrypted); + this.close(); } notesAndTagsCount() { diff --git a/app/assets/javascripts/services/archiveManager.js b/app/assets/javascripts/services/archiveManager.js index 84239b0b3..08b5eb416 100644 --- a/app/assets/javascripts/services/archiveManager.js +++ b/app/assets/javascripts/services/archiveManager.js @@ -29,16 +29,12 @@ export class ArchiveManager { keys = await this.authManager.keys(); authParams = await this.authManager.getAuthParams(); } + const data = await this.__itemsData(items, keys, authParams); + this.__downloadData(data, + `Standard Notes Encrypted Backup - ${this.__formattedDate()}.txt`); + } else { + this.__downloadZippedItems(items); } - this.__itemsData(items, keys, authParams).then((data) => { - const modifier = encrypted ? "Encrypted" : "Decrypted"; - this.__downloadData(data, `Standard Notes ${modifier} Backup - ${this.__formattedDate()}.txt`); - - // download as zipped plain text files - if(!keys) { - this.__downloadZippedItems(items); - } - }); }; if(await this.privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionManageBackups)) { @@ -89,9 +85,19 @@ export class ArchiveManager { __downloadZippedItems(items) { this.__loadZip(() => { - zip.createWriter(new zip.BlobWriter("application/zip"), (zipWriter) => { + zip.createWriter(new zip.BlobWriter("application/zip"), async (zipWriter) => { var index = 0; + const data = await this.modelManager.getJSONDataForItems(items); + await new Promise((resolve) => { + const blob = new Blob([data], {type: 'text/plain'}); + zipWriter.add( + `Standard Notes Backup - ${this.__formattedDate()}.txt`.replace(/:/g, ' '), + new zip.BlobReader(blob), + resolve + ); + }); + const nextFile = () => { var item = items[index]; var name, contents;