A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: force sync & sync progress
thecodrre02f368f4cc8
diff --git a/packages/core/api/sync/collector.js b/packages/core/api/sync/collector.jsindex f6b2cd857..9a39c95c9 100644--- a/packages/core/api/sync/collector.js+++ b/packages/core/api/sync/collector.js@@ -9,20 +9,28 @@ class Collector {this._db = db;}- async collect(lastSyncedTimestamp) {+ async collect(lastSyncedTimestamp, isForceSync) {this._lastSyncedTimestamp = lastSyncedTimestamp;this.key = await this._db.user.getEncryptionKey();return {// notes: this._collect(await this._db.notes.encrypted()),// notebooks: this._collect(await this._db.notebooks.encrypted()),// content: this._collect(await this._db.content.encrypted()),- notes: await this._encrypt(this._collect(this._db.notes.raw)),- notebooks: await this._encrypt(this._collect(this._db.notebooks.raw)),- content: await this._encrypt(this._collect(await this._db.content.all())),+ notes: await this._encrypt(+ this._collect(this._db.notes.raw, isForceSync)+ ),+ notebooks: await this._encrypt(+ this._collect(this._db.notebooks.raw, isForceSync)+ ),+ content: await this._encrypt(+ this._collect(await this._db.content.all(), isForceSync)+ ),attachments: await this._encrypt(- this._collect(this._collect(this._db.attachments.syncable))+ this._collect(this._db.attachments.syncable, isForceSync)+ ),+ settings: await this._encrypt(+ this._collect([this._db.settings.raw], isForceSync)),- settings: await this._encrypt(this._collect([this._db.settings.raw])),vaultKey: await this._serialize(await this._db.vault._getKey()),};}@@ -42,14 +50,15 @@ class Collector {* @param {Array} array* @returns {Array}*/- _collect(array) {+ _collect(array, isForceSync) {if (!array.length) return [];return array.reduce((prev, item) => {if (!item) return prev;+ const isSyncable = !item.synced || isForceSync;if (item.localOnly) {prev.push({ id: item.id, deleted: true, dateModified: Date.now() });} else if (- (item.dateModified > this._lastSyncedTimestamp && !item.synced) ||+ (item.dateModified > this._lastSyncedTimestamp && isSyncable) ||item.migrated) {prev.push(item);diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.jsindex e362170b2..db826c201 100644--- a/packages/core/api/sync/index.js+++ b/packages/core/api/sync/index.js@@ -127,7 +127,7 @@ class Sync {const { lastSynced, oldLastSynced } = await this.init(force);- const { newLastSynced, data } = await this.collect(lastSynced);+ const { newLastSynced, data } = await this.collect(lastSynced, force);const serverResponse = full ? await this.fetch(lastSynced) : null;@@ -170,7 +170,7 @@ class Sync {counter.count++;await this.onSyncItem(syncStatus, counter);- const progress = counter.count;+ const progress = total - counter.count;sendSyncProgressEvent(this.db.eventManager,"download",@@ -198,10 +198,10 @@ class Sync {return serverResponse;}- async collect(lastSynced) {+ async collect(lastSynced, force) {const newLastSynced = Date.now();- let data = await this.collector.collect(lastSynced);+ let data = await this.collector.collect(lastSynced, force);let { syncedAt } = await this.queue.get();if (syncedAt) {