mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: improve content conflict resolution
this fixes the "undefined is not a function" error originated from SparkMD5. Basically, sometimes the remote content or local content is an object — an invalid state. So we need to check for that. (fixes streetwriters/notesnook#371)
This commit is contained in:
@@ -179,17 +179,27 @@ class Merger {
|
|||||||
if (!note || !note.data) return;
|
if (!note || !note.data) return;
|
||||||
note = note.data;
|
note = note.data;
|
||||||
|
|
||||||
// if hashes are equal do nothing
|
const isRemoteObject = typeof remote.data === "object";
|
||||||
if (
|
const isLocalObject = typeof local.data === "object";
|
||||||
!note.locked &&
|
const localHash = isLocalObject ? null : SparkMD5.hash(local.data);
|
||||||
(!remote ||
|
const remoteHash = isRemoteObject ? null : SparkMD5.hash(remote.data);
|
||||||
!local ||
|
if (!note.locked) {
|
||||||
|
// reject all invalid states
|
||||||
|
if (
|
||||||
|
isRemoteObject || // no point in accepting invalid remote object
|
||||||
!local.data ||
|
!local.data ||
|
||||||
!remote.data ||
|
!remote.data ||
|
||||||
remote.data === "undefined" || //TODO not sure about this
|
localHash === remoteHash
|
||||||
SparkMD5.hash(local.data) === SparkMD5.hash(remote.data))
|
)
|
||||||
)
|
return;
|
||||||
return;
|
|
||||||
|
// if we have an invalid content locally but the remote one is valid,
|
||||||
|
// let's accept the remote content.
|
||||||
|
if (isLocalObject && !isRemoteObject) {
|
||||||
|
await this._db.content.add({ id: local.id, ...remote });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (remote.deleted || local.deleted || note.locked) {
|
if (remote.deleted || local.deleted || note.locked) {
|
||||||
// if note is locked or content is deleted we keep the most recent version.
|
// if note is locked or content is deleted we keep the most recent version.
|
||||||
|
|||||||
Reference in New Issue
Block a user