Backups download zip with folders for all content types
This commit is contained in:
@@ -27,12 +27,12 @@ class ArchiveManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.__itemsData(items, keys, authParams).then((data) => {
|
this.__itemsData(items, keys, authParams).then((data) => {
|
||||||
this.__downloadData(data, `SN Archive - ${new Date()}.txt`);
|
let modifier = encrypted ? "Encrypted" : "Decrypted";
|
||||||
|
this.__downloadData(data, `Standard Notes ${modifier} Backup - ${this.__formattedDate()}.txt`);
|
||||||
|
|
||||||
// download as zipped plain text files
|
// download as zipped plain text files
|
||||||
if(!keys) {
|
if(!keys) {
|
||||||
var notes = this.modelManager.allItemsMatchingTypes(["Note"]);
|
this.__downloadZippedItems(items);
|
||||||
this.__downloadZippedNotes(notes);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,16 @@ class ArchiveManager {
|
|||||||
Private
|
Private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
__formattedDate() {
|
||||||
|
var string = `${new Date()}`;
|
||||||
|
// Match up to the first parenthesis, i.e do not include '(Central Standard Time)'
|
||||||
|
var matches = string.match(/^(.*?) \(/);
|
||||||
|
if(matches.length >= 2) {
|
||||||
|
return matches[1]
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
async __itemsData(items, keys, authParams) {
|
async __itemsData(items, keys, authParams) {
|
||||||
let data = await this.modelManager.getJSONDataForItems(items, keys, authParams);
|
let data = await this.modelManager.getJSONDataForItems(items, keys, authParams);
|
||||||
let blobData = new Blob([data], {type: 'text/json'});
|
let blobData = new Blob([data], {type: 'text/json'});
|
||||||
@@ -64,24 +74,40 @@ class ArchiveManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__downloadZippedNotes(notes) {
|
__downloadZippedItems(items) {
|
||||||
this.__loadZip(() => {
|
this.__loadZip(() => {
|
||||||
zip.createWriter(new zip.BlobWriter("application/zip"), (zipWriter) => {
|
zip.createWriter(new zip.BlobWriter("application/zip"), (zipWriter) => {
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
let nextFile = () => {
|
let nextFile = () => {
|
||||||
var note = notes[index];
|
var item = items[index];
|
||||||
var blob = new Blob([note.text], {type: 'text/plain'});
|
var name, contents;
|
||||||
|
|
||||||
var title = note.safeTitle().replace(/\//g, "").replace(/\\+/g, "");
|
if(item.content_type == "Note") {
|
||||||
|
name = item.content.title;
|
||||||
|
contents = item.content.text;
|
||||||
|
} else {
|
||||||
|
name = item.content_type;
|
||||||
|
contents = JSON.stringify(item.content, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
zipWriter.add(`${title}-${note.uuid}.txt`, new zip.BlobReader(blob), () => {
|
var blob = new Blob([contents], {type: 'text/plain'});
|
||||||
|
|
||||||
|
var filePrefix = name.replace(/\//g, "").replace(/\\+/g, "");
|
||||||
|
var fileSuffix = `-${item.uuid.split("-")[0]}.txt`
|
||||||
|
|
||||||
|
// Standard max filename length is 255. Slice the note name down to allow filenameEnd
|
||||||
|
filePrefix = filePrefix.slice(0, (255 - fileSuffix.length));
|
||||||
|
|
||||||
|
let fileName = `${item.content_type}/${filePrefix}${fileSuffix}`
|
||||||
|
|
||||||
|
zipWriter.add(fileName, new zip.BlobReader(blob), () => {
|
||||||
index++;
|
index++;
|
||||||
if(index < notes.length) {
|
if(index < items.length) {
|
||||||
nextFile();
|
nextFile();
|
||||||
} else {
|
} else {
|
||||||
zipWriter.close((blob) => {
|
zipWriter.close((blob) => {
|
||||||
this.__downloadData(blob, `Notes Txt Archive - ${new Date()}.zip`)
|
this.__downloadData(blob, `Standard Notes Backup - ${this.__formattedDate()}.zip`);
|
||||||
zipWriter = null;
|
zipWriter = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@
|
|||||||
Decrypted
|
Decrypted
|
||||||
|
|
||||||
.button-group
|
.button-group
|
||||||
.button.info{"ng-click" => "downloadDataArchive()", "ng-class" => "{'mt-5' : !user}"}
|
.button.info{"ng-click" => "downloadDataArchive()"}
|
||||||
.label Download Backup
|
.label Download Backup
|
||||||
|
|
||||||
%label.button.info
|
%label.button.info
|
||||||
|
|||||||
Reference in New Issue
Block a user