π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Gen
Manav Rathibe046cd906af
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.tsindex 90fd9458f6..8dd08a6d58 100644--- a/web/packages/new/photos/services/collections.ts+++ b/web/packages/new/photos/services/collections.ts@@ -346,7 +346,7 @@ async function getLastTrashSyncTime() {}export async function syncTrash(collections: Collection[],- setTrashedFiles: (fs: EnteFile[]) => void,+ setTrashedFiles: ((fs: EnteFile[]) => void) | undefined,): Promise<void> {const trash = await getLocalTrash();collections = [...collections, ...(await getLocalDeletedCollections())];@@ -370,7 +370,7 @@ export async function syncTrash(export const updateTrash = async (collections: Map<number, Collection>,sinceTime: number,- setTrashedFiles: (fs: EnteFile[]) => void,+ setTrashedFiles: ((fs: EnteFile[]) => void) | undefined,currentTrash: Trash,): Promise<Trash> => {try {@@ -416,7 +416,7 @@ export const updateTrash = async (time = resp.data.diff.slice(-1)[0].updatedAt;}- setTrashedFiles(getTrashedFiles(updatedTrash));+ setTrashedFiles?.(getTrashedFiles(updatedTrash));await localForage.setItem(TRASH, updatedTrash);await localForage.setItem(TRASH_TIME, time);} while (resp.data.hasMore);diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.tsindex 25ad49ed26..61c1e4e90b 100644--- a/web/packages/new/photos/services/files.ts+++ b/web/packages/new/photos/services/files.ts@@ -70,15 +70,15 @@ export const setLocalFiles = async (export const syncFiles = async (type: "normal" | "hidden",collections: Collection[],- onResetFiles: (fs: EnteFile[]) => void,- onFetchFiles: (fs: EnteFile[]) => void,+ onResetFiles: ((files: EnteFile[]) => void) | undefined,+ onFetchFiles: ((files: EnteFile[]) => void) | undefined,) => {const localFiles = await getLocalFiles(type);let files = removeDeletedCollectionFiles(collections, localFiles);let didUpdateFiles = false;if (files.length !== localFiles.length) {await setLocalFiles(type, files);- onResetFiles(files);+ onResetFiles?.(files);didUpdateFiles = true;}for (const collection of collections) {@@ -103,7 +103,7 @@ export const syncFiles = async (export const getFiles = async (collection: Collection,sinceTime: number,- onFetchFiles: (fs: EnteFile[]) => void,+ onFetchFiles: ((fs: EnteFile[]) => void) | undefined,): Promise<EnteFile[]> => {try {let decryptedFiles: EnteFile[] = [];@@ -132,7 +132,7 @@ export const getFiles = async ();decryptedFiles = [...decryptedFiles, ...newDecryptedFilesBatch];- onFetchFiles(decryptedFiles);+ onFetchFiles?.(decryptedFiles);// eslint-disable-next-line @typescript-eslint/no-unsafe-member-accessif (resp.data.diff.length) {// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-accessdiff --git a/web/packages/new/photos/services/sync.ts b/web/packages/new/photos/services/sync.tsindex 5f215ca857..eaf08b949d 100644--- a/web/packages/new/photos/services/sync.ts+++ b/web/packages/new/photos/services/sync.ts@@ -1,5 +1,5 @@-/* eslint-disable @typescript-eslint/no-empty-function */import { resetFileViewerDataSourceOnClose } from "@/gallery/components/viewer/data-source";+import type { EnteFile } from "@/media/file";import { isHiddenCollection } from "@/new/photos/services/collection";import {getAllLatestCollections,@@ -44,6 +44,31 @@ export const sync = async () => {void mlSync();};+interface SyncFilesAndCollectionsOpts {+ /**+ * Called when saved normal files were replaced by the given {@link files}.+ */+ onResetFiles: (files: EnteFile[]) => void;+ /**+ * Called when saved normal files were augmented with the newly fetched+ * {@link files}.+ */+ onFetchFiles: (files: EnteFile[]) => void;+ /**+ * Called when saved hidden files were replaced by the given {@link files}.+ */+ onResetHiddenFiles: (files: EnteFile[]) => void;+ /**+ * Called when saved hidden files were augmented with the newly fetched+ * {@link files}.+ */+ onFetchHiddenFiles: (files: EnteFile[]) => void;+ /**+ * Called when saved trashed files were replaced by the given {@link files}.+ */+ onResetTrashedFiles: (files: EnteFile[]) => void;+}+/*** Sync our local file and collection state with remote.*@@ -52,12 +77,17 @@ export const sync = async () => {* request that modified collections or files, and so now want to sync our local* changes to match remote).*- * A bespoke version of this in currently used by the gallery component when it- * syncs - it needs a broken down, bespoke version because it also keeps local- * state variables that need to be updated with the various callbacks that we- * ignore in this version.+ * It takes various optional callbacks that are used by gallery to update its+ * local state in tandem with the sync. The callbacks are optional since we+ * might not have local state to update, as is the case when this is invoked+ * post dedup.+ *+ * @returns `true` if one or more normal or hidden files were updated during the+ * sync.*/-export const syncFilesAndCollections = async () => {+export const syncFilesAndCollections = async (+ opts?: SyncFilesAndCollectionsOpts,+) => {const allCollections = await getAllLatestCollections();const [hiddenCollections, normalCollections] = splitByPredicate(allCollections,@@ -66,20 +96,23 @@ export const syncFilesAndCollections = async () => {const didUpdateNormalFiles = await syncFiles("normal",normalCollections,- () => {},- () => {},+ opts?.onResetFiles,+ opts?.onFetchFiles,);const didUpdateHiddenFiles = await syncFiles("hidden",hiddenCollections,- () => {},- () => {},+ opts?.onResetHiddenFiles,+ opts?.onFetchHiddenFiles,);- await syncTrash(allCollections, () => {});+ await syncTrash(allCollections, opts?.onResetTrashedFiles);if (didUpdateNormalFiles || didUpdateHiddenFiles) {- // TODO: Ok for now since we're only called by deduper, but still needs- // fixing instead of a hidden gotcha.+ // TODO: Ok for now since its is only commented for the deduper (gallery+ // does this on the return value), but still needs fixing instead of a+ // hidden gotcha.// exportService.onLocalFilesUpdated();resetFileViewerDataSourceOnClose();+ return true;}+ return false;};