fix: content type being set to "content" during sync

this bug broke export/publishing & basically
everything that depends on content type
to function.
This commit is contained in:
thecodrr
2022-08-06 10:45:15 +05:00
parent 62b715645f
commit cf9bad7db8
4 changed files with 15 additions and 8 deletions

View File

@@ -47,7 +47,7 @@ class Collector {
* @param {Array} array
* @returns {Array}
*/
_collect(type, array, isForceSync) {
_collect(collectionId, array, isForceSync) {
if (!array.length) return [];
const result = array.reduce((prev, item) => {
@@ -60,18 +60,18 @@ class Collector {
if (item.localOnly) {
prev.push({
id: item.id,
type,
collectionId,
deleted: true,
dateModified: Date.now(),
});
} else if (isUnsynced && isSyncable) {
prev.push({ ...item, type });
prev.push({ ...item, collectionId });
}
return prev;
}, []);
this.logger.info(
`Collected items: ${type} (${result.length}/${array.length})`
`Collected items: ${collectionId} (${result.length}/${array.length})`
);
return result;
}

View File

@@ -257,7 +257,9 @@ class Sync {
const arrays = data.items.reduce(
(arrays, item) => {
arrays.types.push(item.type);
arrays.types.push(item.collectionId);
delete item.collectionId;
arrays.items.push(item);
return arrays;
},

View File

@@ -107,7 +107,11 @@ class Merger {
if (deserialized.alg && deserialized.cipher) return deserialized;
let type = deserialized.type;
if (!type && deserialized.data) type = "tiptap";
// temporary fix for streetwriters/notesnook#751
if (type === "content") {
type = "tiptap";
deserialized.type = type;
}
if (!migrations[version]) {
throw new Error(
@@ -119,7 +123,6 @@ class Merger {
const migrate = migrations[version][type];
if (migrate) {
console.log(migrate, version, type);
return migrate(deserialized);
}
return deserialized;

View File

@@ -5,6 +5,8 @@ export function getContentFromData(type, data) {
case "tiptap":
return new Tiptap(data);
default:
return null;
throw new Error(
`Unknown content type: "${type}". Please report this error at support@streetwriters.co.`
);
}
}