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
core: download all attachments when full offline mode is on
Abdullah Atta57ddaafc169e
diff --git a/packages/core/src/api/sync/index.ts b/packages/core/src/api/sync/index.tsindex ad7d7a548..9f9f90439 100644--- a/packages/core/src/api/sync/index.ts+++ b/packages/core/src/api/sync/index.ts@@ -245,6 +245,21 @@ class Sync {this.logger.info("Stopping sync");await this.db.setLastSynced(Date.now());this.db.eventManager.publish(EVENTS.syncCompleted);++ if (await this.db.kv().read("fullOfflineMode")) {+ const attachments = await this.db.attachments.linked+ .fields(["attachments.id", "attachments.hash", "attachments.chunkSize"])+ .items();++ await this.db.fs().queueDownloads(+ attachments.map((a) => ({+ filename: a.hash,+ chunkSize: a.chunkSize+ })),+ "download-all-attachments",+ { readOnDownload: false }+ );+ }}async cancel() {diff --git a/packages/core/src/collections/attachments.ts b/packages/core/src/collections/attachments.tsindex f52c59a03..caac855e1 100644--- a/packages/core/src/collections/attachments.ts+++ b/packages/core/src/collections/attachments.ts@@ -497,6 +497,22 @@ export class Attachments implements ICollection {this.db.options?.batchSize);}++ get linked() {+ return this.collection.createFilter<Attachment>(+ (qb) =>+ qb+ .where(isFalse("deleted"))+ .where("id", "in", (eb) =>+ eb+ .selectFrom("relations")+ .where("toType", "==", "attachment")+ .select("toId as id")+ .$narrowType<{ id: string }>()+ ),+ this.db.options?.batchSize+ );+ }// get media() {// return this.all.filter(// (attachment) =>diff --git a/packages/core/src/database/kv.ts b/packages/core/src/database/kv.tsindex 5eb6c9174..a67e20511 100644--- a/packages/core/src/database/kv.ts+++ b/packages/core/src/database/kv.ts@@ -29,6 +29,7 @@ interface KV {monographs: string[];deviceId: string;lastBackupTime: number;+ fullOfflineMode: boolean;}export const KEYS: (keyof KV)[] = [@@ -38,7 +39,8 @@ export const KEYS: (keyof KV)[] = ["token","monographs","deviceId",- "lastBackupTime"+ "lastBackupTime",+ "fullOfflineMode"];export class KVStorage {