π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
both
Manav Rathicb148ea3b13e
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex 14da19691a..17e45a4236 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -11,19 +11,22 @@ import { expose } from "comlink";import downloadManager from "../download";import { getAllLocalFiles, getLocalTrashedFiles } from "../files";import type { UploadItem } from "../upload/types";-import { imageBitmapAndData } from "./bitmap";+import { imageBitmapAndData, type ImageBitmapAndData } from "./bitmap";+import { indexCLIP, type CLIPIndex } from "./clip";import {indexableFileIDs,markIndexingFailed,+ saveCLIPIndex,saveFaceIndex,updateAssumingLocalFiles,} from "./db";import {pullCLIPEmbeddings,pullFaceEmbeddings,+ putCLIPIndex,putFaceIndex,} from "./embedding";-import { type FaceIndex, indexFaces } from "./face";+import { indexFaces, type FaceIndex } from "./face";import type { MLWorkerElectron } from "./worker-electron";const idleDurationStart = 5; /* 5 seconds */@@ -360,6 +363,32 @@ const index = async (const startTime = Date.now();const image = await imageBitmapAndData(enteFile, uploadItem, electron);+ const res = await Promise.allSettled([+ _indexFace(f, enteFile, image, electron, userAgent),+ // TODO-ML: clip-test+ _indexCLIP(f, enteFile, image, electron, userAgent),+ ]);+ image.bitmap.close();++ const msg: string[] = [];+ for (const r of res) {+ if (r.status == "rejected") throw r.reason;+ else msg.push(r.value);+ }++ log.debug(() => {+ const ms = Date.now() - startTime;+ return `Indexed ${msg.join(" and ")} in ${f} (${ms} ms)`;+ });+};++const _indexFace = async (+ f: string,+ enteFile: EnteFile,+ image: ImageBitmapAndData,+ electron: MLWorkerElectron,+ userAgent: string,+) => {let faceIndex: FaceIndex;try {faceIndex = await indexFaces(enteFile, image, electron, userAgent);@@ -367,8 +396,6 @@ const index = async (log.error(`Failed to index faces in ${f}`, e);await markIndexingFailed(enteFile.id);throw e;- } finally {- image.bitmap.close();}// [Note: Transient and permanent indexing failures]@@ -410,9 +437,36 @@ const index = async (throw e;}- log.debug(() => {- const nf = faceIndex.faceEmbedding.faces.length;- const ms = Date.now() - startTime;- return `Indexed ${nf} faces in ${f} (${ms} ms)`;- });+ // A message for debug printing.+ return `${faceIndex.faceEmbedding.faces.length} faces`;+};++const _indexCLIP = async (+ f: string,+ enteFile: EnteFile,+ image: ImageBitmapAndData,+ electron: MLWorkerElectron,+ userAgent: string,+) => {+ let clipIndex: CLIPIndex;+ try {+ clipIndex = await indexCLIP(enteFile, image, electron, userAgent);+ } catch (e) {+ log.error(`Failed to index CLIP in ${f}`, e);+ await markIndexingFailed(enteFile.id);+ throw e;+ }++ // See: [Note: Transient and permanent indexing failures]+ try {+ await putCLIPIndex(enteFile, clipIndex);+ await saveCLIPIndex(clipIndex);+ } catch (e) {+ log.error(`Failed to put/save CLIP index for ${f}`, e);+ if (isHTTP4xxError(e)) await markIndexingFailed(enteFile.id);+ throw e;+ }++ // A message for debug printing.+ return "clip";};