mobile: add support for offline mode, backup with attachments

This commit is contained in:
Ammar Ahmed
2024-07-31 15:44:18 +05:00
committed by Abdullah Atta
parent b6021dc76b
commit d12ed967e3
24 changed files with 1068 additions and 715 deletions

View File

@@ -254,7 +254,7 @@ class Database {
this.sql().withTables(),
new NNMigrationProvider()
);
await this.onInit(this.sql() as Kysely<RawDatabaseSchema>);
await this.onInit(this.sql() as unknown as Kysely<RawDatabaseSchema>);
await this.initCollections();
return true;
}

View File

@@ -57,6 +57,7 @@ import { DefaultColors } from "../../collections/colors";
export type SyncOptions = {
type: "full" | "fetch" | "send";
force?: boolean;
offlineMode?: boolean;
};
export default class SyncManager {
@@ -246,7 +247,7 @@ class Sync {
await this.db.setLastSynced(Date.now());
this.db.eventManager.publish(EVENTS.syncCompleted);
if (await this.db.kv().read("fullOfflineMode")) {
if (options.offlineMode) {
const attachments = await this.db.attachments.linked
.fields(["attachments.id", "attachments.hash", "attachments.chunkSize"])
.items();

View File

@@ -33,6 +33,7 @@ export class Crypto {
export function isCipher(item: any): item is Cipher<"base64"> {
return (
item !== null &&
typeof item === "object" &&
"cipher" in item &&
"iv" in item &&