fix: bundle files together when exporting a decrypted backup

This commit is contained in:
Baptiste Grob
2020-07-21 18:02:33 +02:00
parent c906603634
commit b888e68c5a
2 changed files with 17 additions and 10 deletions

View File

@@ -445,6 +445,7 @@ class AccountMenuCtrl extends PureCtrl {
async downloadDataArchive() { async downloadDataArchive() {
this.archiveManager.downloadBackup(this.state.mutable.backupEncrypted); this.archiveManager.downloadBackup(this.state.mutable.backupEncrypted);
this.close();
} }
notesAndTagsCount() { notesAndTagsCount() {

View File

@@ -29,16 +29,12 @@ export class ArchiveManager {
keys = await this.authManager.keys(); keys = await this.authManager.keys();
authParams = await this.authManager.getAuthParams(); 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)) { if(await this.privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionManageBackups)) {
@@ -89,9 +85,19 @@ export class ArchiveManager {
__downloadZippedItems(items) { __downloadZippedItems(items) {
this.__loadZip(() => { this.__loadZip(() => {
zip.createWriter(new zip.BlobWriter("application/zip"), (zipWriter) => { zip.createWriter(new zip.BlobWriter("application/zip"), async (zipWriter) => {
var index = 0; 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 = () => { const nextFile = () => {
var item = items[index]; var item = items[index];
var name, contents; var name, contents;