π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Regen upper
Manav Rathib950fde3f22d
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex e3c2b616b4..fb784755f4 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -9,9 +9,11 @@ import {} from "@/new/photos/services/feature-flags";import type { EnteFile } from "@/new/photos/types/file";import { clientPackageName, isDesktop } from "@/next/app";+import { blobCache } from "@/next/blob-cache";import { ensureElectron } from "@/next/electron";import log from "@/next/log";import { ComlinkWorker } from "@/next/worker/comlink-worker";+import { regenerateFaceCrops } from "./crop";import { clearFaceDB, faceIndex, indexableAndIndexedCounts } from "./db";import { MLWorker } from "./worker";@@ -233,3 +235,22 @@ export const unidentifiedFaceIDs = async (const index = await faceIndex(enteFile.id);return index?.faceEmbedding.faces.map((f) => f.faceID) ?? [];};++/**+ * Check to see if any of the faces in the given file do not have a face crop+ * present locally. If so, then regenerate the face crops for all the faces in+ * the file (updating the "face-crops" {@link BlobCache}).+ */+export const regenerateFaceCropsIfNeeded = async (enteFile: EnteFile) => {+ const index = await faceIndex(enteFile.id);+ if (!index) return;++ const faceIDs = index.faceEmbedding.faces.map((f) => f.faceID);+ const cache = await blobCache("face-crops");+ for (const id of faceIDs) {+ if (!(await cache.has(id))) {+ await regenerateFaceCrops(enteFile, index);+ break;+ }+ }+};diff --git a/web/packages/next/blob-cache.ts b/web/packages/next/blob-cache.tsindex 0db9464521..750f3effd8 100644--- a/web/packages/next/blob-cache.ts+++ b/web/packages/next/blob-cache.ts@@ -56,6 +56,10 @@ export interface BlobCache {* Get the data corresponding to {@link key} (if found) from the cache.*/get: (key: string) => Promise<Blob | undefined>;+ /**+ * Check if there is an item corresponding to {@link key} in the cache.+ */+ has: (key: string) => Promise<boolean>;/*** Add the given {@link key}-value ({@link blob}) pair to the cache.*/@@ -153,6 +157,7 @@ const openWebCache = async (name: BlobCacheNamespace) => {const res = await cache.match(key);return await res?.blob();},+ has: async (key: string) => cache.match(key).then((v) => !!v),put: (key: string, blob: Blob) => cache.put(key, new Response(blob)),delete: (key: string) => cache.delete(key),};@@ -184,6 +189,16 @@ const openOPFSCacheWeb = async (name: BlobCacheNamespace) => {throw e;}},+ has: async (key: string) => {+ try {+ await cache.getFileHandle(key);+ return true;+ } catch (e) {+ if (e instanceof DOMException && e.name == "NotFoundError")+ return false;+ throw e;+ }+ },put: async (key: string, blob: Blob) => {const fileHandle = await cache.getFileHandle(key, {create: true,@@ -205,25 +220,6 @@ const openOPFSCacheWeb = async (name: BlobCacheNamespace) => {};};-/**- * Return a cached blob for {@link key} in {@link cacheName}. If the blob is not- * found in the cache, recreate/fetch it using {@link get}, cache it, and then- * return it.- */-export const cachedOrNew = async (- cacheName: BlobCacheNamespace,- key: string,- get: () => Promise<Blob>,-): Promise<Blob> => {- const cache = await openBlobCache(cacheName);- const cachedBlob = await cache.get(key);- if (cachedBlob) return cachedBlob;-- const blob = await get();- await cache.put(key, blob);- return blob;-};-/*** Delete all cached data, including cached caches.*