mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: notebooks aren't imported from backup
This commit is contained in:
@@ -130,4 +130,16 @@ export default class Notebooks extends Collection {
|
|||||||
await this._db.trash.add(notebookData);
|
await this._db.trash.add(notebookData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
for (let notebook of this.all) {
|
||||||
|
for (let topic of notebook.topics) {
|
||||||
|
const clonedIds = topic.notes.slice();
|
||||||
|
topic.notes = [];
|
||||||
|
for (let noteId of clonedIds) {
|
||||||
|
if (!!this._db.notes.note(noteId)) topic.notes.push(noteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ export default class Backup {
|
|||||||
"This backup was made from a newer version of Notesnook. Cannot migrate."
|
"This backup was made from a newer version of Notesnook. Cannot migrate."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// we have to reindex to make sure we handle all the items
|
||||||
|
// properly.
|
||||||
|
reindex(data);
|
||||||
const collections = [
|
const collections = [
|
||||||
{
|
{
|
||||||
index: data["notebooks"],
|
index: data["notebooks"],
|
||||||
@@ -138,7 +141,9 @@ export default class Backup {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
await this._migrator.migrate(collections, (id) => data[id], version);
|
if (await this._migrator.migrate(collections, (id) => data[id], version)) {
|
||||||
|
this._db.notebooks.cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_validate(backup) {
|
_validate(backup) {
|
||||||
@@ -174,3 +179,23 @@ function filterData(data) {
|
|||||||
skippedKeys.forEach((key) => delete data[key]);
|
skippedKeys.forEach((key) => delete data[key]);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reindex(data) {
|
||||||
|
for (let key in data) {
|
||||||
|
const item = data[key];
|
||||||
|
switch (item.type) {
|
||||||
|
case "notebook":
|
||||||
|
if (!data["notebooks"]) data["notebooks"] = [];
|
||||||
|
data["notebooks"].push(item.id);
|
||||||
|
break;
|
||||||
|
case "note":
|
||||||
|
if (!data["notes"]) data["notes"] = [];
|
||||||
|
data["notes"].push(item.id);
|
||||||
|
break;
|
||||||
|
case "content":
|
||||||
|
if (!data["content"]) data["content"] = [];
|
||||||
|
data["content"].push(item.id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user