mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
core: download all attachments when full offline mode is on
This commit is contained in:
committed by
Abdullah Atta
parent
e4a755c69f
commit
57ddaafc16
@@ -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() {
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user