π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Consolidate types
Manav Rathi068ed78fe03c
diff --git a/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx b/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsxindex 6ebc0d9422..9b5d59eacd 100644--- a/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx+++ b/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx@@ -5,7 +5,7 @@ import { t } from "i18next";import { AppContext } from "pages/_app";import { useContext } from "react";import { components } from "react-select";-import { IndexStatus } from "types/machineLearning/ui";+import { IndexStatus } from "utils/storage/mlIDbStorage";import { Suggestion, SuggestionType } from "types/search";const { Menu } = components;diff --git a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsxindex 3f737b3e0c..3b995b8499 100644--- a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx+++ b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx@@ -17,7 +17,7 @@ import {import { Collection } from "types/collection";import { LocationTagData } from "types/entity";import { EnteFile } from "types/file";-import { Person } from "types/machineLearning";+import { Person } from "services/ml/types";import {ClipSearchScores,DateValue,diff --git a/web/apps/photos/src/components/ml/PeopleList.tsx b/web/apps/photos/src/components/ml/PeopleList.tsxindex 4691d4b650..ea317fbec6 100644--- a/web/apps/photos/src/components/ml/PeopleList.tsx+++ b/web/apps/photos/src/components/ml/PeopleList.tsx@@ -4,7 +4,7 @@ import { Legend } from "components/PhotoViewer/styledComponents/Legend";import { t } from "i18next";import React, { useEffect, useState } from "react";import { EnteFile } from "types/file";-import { Face, Person } from "types/machineLearning";+import { Face, Person } from "services/ml/types";import { getPeopleList, getUnidentifiedFaces } from "utils/machineLearning";const FaceChipContainer = styled("div")`diff --git a/web/apps/photos/src/constants/mlConfig.ts b/web/apps/photos/src/constants/mlConfig.tsindex 929594e1c1..d8aaeb4104 100644--- a/web/apps/photos/src/constants/mlConfig.ts+++ b/web/apps/photos/src/constants/mlConfig.ts@@ -1,5 +1,5 @@import { JobConfig } from "types/common/job";-import { MLSearchConfig, MLSyncConfig } from "types/machineLearning";+import { MLSearchConfig, MLSyncConfig } from "services/ml/types";export const DEFAULT_ML_SYNC_JOB_CONFIG: JobConfig = {intervalSec: 5,diff --git a/web/apps/photos/src/services/machineLearning/arcfaceAlignmentService.ts b/web/apps/photos/src/services/machineLearning/arcfaceAlignmentService.tsindex 99063b3f25..1d7deac5e2 100644--- a/web/apps/photos/src/services/machineLearning/arcfaceAlignmentService.ts+++ b/web/apps/photos/src/services/machineLearning/arcfaceAlignmentService.ts@@ -4,7 +4,7 @@ import {FaceAlignmentService,FaceDetection,Versioned,-} from "types/machineLearning";+} from "services/ml/types";import { getArcfaceAlignment } from "utils/machineLearning/faceAlign";class ArcfaceAlignmentService implements FaceAlignmentService {diff --git a/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts b/web/apps/photos/src/services/machineLearning/arcfaceCropService.tsindex cb6ccd0298..f5e1e835a6 100644--- a/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts+++ b/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts@@ -5,7 +5,7 @@ import {FaceCropService,FaceDetection,Versioned,-} from "types/machineLearning";+} from "services/ml/types";import { getArcfaceAlignment } from "utils/machineLearning/faceAlign";import { getFaceCrop } from "utils/machineLearning/faceCrop";diff --git a/web/apps/photos/src/services/machineLearning/clusteringService.ts b/web/apps/photos/src/services/machineLearning/clusteringService.tsindex 03931b63b8..32c25f698c 100644--- a/web/apps/photos/src/services/machineLearning/clusteringService.ts+++ b/web/apps/photos/src/services/machineLearning/clusteringService.ts@@ -8,7 +8,7 @@ import {ClusteringResults,HdbscanResults,Versioned,-} from "types/machineLearning";+} from "services/ml/types";class ClusteringService {private dbscan: DBSCAN;diff --git a/web/apps/photos/src/services/machineLearning/dbscanClusteringService.ts b/web/apps/photos/src/services/machineLearning/dbscanClusteringService.tsindex 33298eef3c..57d181de4f 100644--- a/web/apps/photos/src/services/machineLearning/dbscanClusteringService.ts+++ b/web/apps/photos/src/services/machineLearning/dbscanClusteringService.ts@@ -6,7 +6,7 @@ import {ClusteringService,HdbscanResults,Versioned,-} from "types/machineLearning";+} from "services/ml/types";class DbscanClusteringService implements ClusteringService {public method: Versioned<ClusteringMethod>;diff --git a/web/apps/photos/src/services/machineLearning/faceService.ts b/web/apps/photos/src/services/machineLearning/faceService.tsindex 1dedadf151..6bb045ae2b 100644--- a/web/apps/photos/src/services/machineLearning/faceService.ts+++ b/web/apps/photos/src/services/machineLearning/faceService.ts@@ -5,7 +5,7 @@ import {Face,MLSyncContext,MLSyncFileContext,-} from "types/machineLearning";+} from "services/ml/types";import { imageBitmapToBlob } from "utils/image";import {areFaceIdsSame,diff --git a/web/apps/photos/src/services/machineLearning/hdbscanClusteringService.ts b/web/apps/photos/src/services/machineLearning/hdbscanClusteringService.tsindex 21e2118252..0671b0bde1 100644--- a/web/apps/photos/src/services/machineLearning/hdbscanClusteringService.ts+++ b/web/apps/photos/src/services/machineLearning/hdbscanClusteringService.ts@@ -6,7 +6,7 @@ import {ClusteringService,HdbscanResults,Versioned,-} from "types/machineLearning";+} from "services/ml/types";class HdbscanClusteringService implements ClusteringService {public method: Versioned<ClusteringMethod>;diff --git a/web/apps/photos/src/services/machineLearning/laplacianBlurDetectionService.ts b/web/apps/photos/src/services/machineLearning/laplacianBlurDetectionService.tsindex 3357e21ccd..f1d7bf5008 100644--- a/web/apps/photos/src/services/machineLearning/laplacianBlurDetectionService.ts+++ b/web/apps/photos/src/services/machineLearning/laplacianBlurDetectionService.ts@@ -3,7 +3,7 @@ import {BlurDetectionService,Face,Versioned,-} from "types/machineLearning";+} from "services/ml/types";import { createGrayscaleIntMatrixFromNormalized2List } from "utils/image";import { mobileFaceNetFaceSize } from "./mobileFaceNetEmbeddingService";diff --git a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts b/web/apps/photos/src/services/machineLearning/machineLearningFactory.tsindex 991ae68087..999bae8fe9 100644--- a/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts+++ b/web/apps/photos/src/services/machineLearning/machineLearningFactory.ts@@ -4,7 +4,6 @@ import { ComlinkWorker } from "@/next/worker/comlink-worker";import { getDedicatedCryptoWorker } from "@ente/shared/crypto";import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker";import PQueue from "p-queue";-import { EnteFile } from "types/file";import {BlurDetectionMethod,BlurDetectionService,@@ -22,7 +21,8 @@ import {MLLibraryData,MLSyncConfig,MLSyncContext,-} from "types/machineLearning";+} from "services/ml/types";+import { EnteFile } from "types/file";import { logQueueStats } from "utils/machineLearning";import arcfaceAlignmentService from "./arcfaceAlignmentService";import arcfaceCropService from "./arcfaceCropService";diff --git a/web/apps/photos/src/services/machineLearning/machineLearningService.ts b/web/apps/photos/src/services/machineLearning/machineLearningService.tsindex 03a3b7e2c7..f2354f7b13 100644--- a/web/apps/photos/src/services/machineLearning/machineLearningService.ts+++ b/web/apps/photos/src/services/machineLearning/machineLearningService.ts@@ -6,13 +6,13 @@ import { MAX_ML_SYNC_ERROR_COUNT } from "constants/mlConfig";import downloadManager from "services/download";import { putEmbedding } from "services/embeddingService";import { getLocalFiles } from "services/fileService";-import { EnteFile } from "types/file";import {MLSyncContext,MLSyncFileContext,MLSyncResult,MlFileData,-} from "types/machineLearning";+} from "services/ml/types";+import { EnteFile } from "types/file";import { getMLSyncConfig } from "utils/machineLearning/config";import { LocalFileMlDataToServerFileMl } from "utils/machineLearning/mldataMappers";import mlIDbStorage from "utils/storage/mlIDbStorage";diff --git a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts b/web/apps/photos/src/services/machineLearning/mlWorkManager.tsindex d1c5e9db5e..c75d4b14a0 100644--- a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts+++ b/web/apps/photos/src/services/machineLearning/mlWorkManager.ts@@ -5,9 +5,9 @@ import { eventBus, Events } from "@ente/shared/events";import { getToken, getUserID } from "@ente/shared/storage/localStorage/helpers";import debounce from "debounce";import PQueue from "p-queue";+import { MLSyncResult } from "services/ml/types";import { JobResult } from "types/common/job";import { EnteFile } from "types/file";-import { MLSyncResult } from "types/machineLearning";import { getDedicatedMLWorker } from "utils/comlink/ComlinkMLWorker";import { SimpleJob } from "utils/common/job";import { logQueueStats } from "utils/machineLearning";diff --git a/web/apps/photos/src/services/machineLearning/mobileFaceNetEmbeddingService.ts b/web/apps/photos/src/services/machineLearning/mobileFaceNetEmbeddingService.tsindex 818b8a5d12..1b2205801e 100644--- a/web/apps/photos/src/services/machineLearning/mobileFaceNetEmbeddingService.ts+++ b/web/apps/photos/src/services/machineLearning/mobileFaceNetEmbeddingService.ts@@ -4,7 +4,7 @@ import {FaceEmbeddingMethod,FaceEmbeddingService,Versioned,-} from "types/machineLearning";+} from "services/ml/types";export const mobileFaceNetFaceSize = 112;diff --git a/web/apps/photos/src/services/machineLearning/peopleService.ts b/web/apps/photos/src/services/machineLearning/peopleService.tsindex ad7d7bcec3..f4ed5104bb 100644--- a/web/apps/photos/src/services/machineLearning/peopleService.ts+++ b/web/apps/photos/src/services/machineLearning/peopleService.ts@@ -1,5 +1,5 @@import log from "@/next/log";-import { Face, MLSyncContext, Person } from "types/machineLearning";+import { Face, MLSyncContext, Person } from "services/ml/types";import {findFirstIfSorted,getAllFacesFromMap,diff --git a/web/apps/photos/src/services/machineLearning/readerService.ts b/web/apps/photos/src/services/machineLearning/readerService.tsindex 62aebdbd1f..44d0738f51 100644--- a/web/apps/photos/src/services/machineLearning/readerService.ts+++ b/web/apps/photos/src/services/machineLearning/readerService.ts@@ -1,6 +1,6 @@import { FILE_TYPE } from "@/media/file-type";import log from "@/next/log";-import { MLSyncContext, MLSyncFileContext } from "types/machineLearning";+import { MLSyncContext, MLSyncFileContext } from "services/ml/types";import {getLocalFileImageBitmap,getOriginalImageBitmap,diff --git a/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts b/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.tsindex 4fa840749d..b9a2ed1b6b 100644--- a/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts+++ b/web/apps/photos/src/services/machineLearning/yoloFaceDetectionService.ts@@ -1,5 +1,11 @@import { workerBridge } from "@/next/worker/worker-bridge";import { euclidean } from "hdbscan";+import {+ FaceDetection,+ FaceDetectionMethod,+ FaceDetectionService,+ Versioned,+} from "services/ml/types";import {Matrix,applyToPoint,@@ -8,12 +14,6 @@ import {translate,} from "transformation-matrix";import { Dimensions } from "types/image";-import {- FaceDetection,- FaceDetectionMethod,- FaceDetectionService,- Versioned,-} from "types/machineLearning";import {clamp,getPixelBilinear,diff --git a/web/apps/photos/src/types/machineLearning/index.ts b/web/apps/photos/src/services/ml/types.tssimilarity index 89%rename from web/apps/photos/src/types/machineLearning/index.tsrename to web/apps/photos/src/services/ml/types.tsindex 2c3961cdf6..1c95717f50 100644--- a/web/apps/photos/src/types/machineLearning/index.ts+++ b/web/apps/photos/src/services/ml/types.ts@@ -329,3 +329,46 @@ export interface MachineLearningWorker {close(): void;}++export interface ClipEmbedding {+ embedding: Float32Array;+ model: "ggml-clip" | "onnx-clip";+}++/// [`x`] and [y] are the coordinates of the top left corner of the box, so the minimim values+/// [width] and [height] are the width and height of the box.+/// All values are in absolute pixels relative to the original image size.+export interface CenterBox {+ x: number;+ y: number;+ height: number;+ width: number;+}++export interface DetectionPoint {+ x: number;+ y: number;+}++export interface Detection {+ box: CenterBox;+ landmarks: DetectionPoint[];+}++export interface FileMLFace {+ id: string;+ confidence: number;+ blur: number;+ embedding: Float32Array;+ detection: Detection;+}++export interface FileML {+ fileID: number;+ clip?: ClipEmbedding;+ faces: Face[];+ height: number;+ width: number;+ version: number;+ error?: string;+}diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.tsindex 96c574b9dd..7c00dec724 100644--- a/web/apps/photos/src/services/searchService.ts+++ b/web/apps/photos/src/services/searchService.ts@@ -2,10 +2,10 @@ import { FILE_TYPE } from "@/media/file-type";import log from "@/next/log";import * as chrono from "chrono-node";import { t } from "i18next";+import { Person } from "services/ml/types";import { Collection } from "types/collection";import { EntityType, LocationTag, LocationTagData } from "types/entity";import { EnteFile } from "types/file";-import { Person } from "types/machineLearning";import {ClipSearchScores,DateValue,diff --git a/web/apps/photos/src/types/machineLearning/data/clip.ts b/web/apps/photos/src/types/machineLearning/data/clip.tsdeleted file mode 100644index 0181e89e57..0000000000--- a/web/apps/photos/src/types/machineLearning/data/clip.ts+++ /dev/null@@ -1,4 +0,0 @@-export interface ClipEmbedding {- embedding: Float32Array;- model: "ggml-clip" | "onnx-clip";-}diff --git a/web/apps/photos/src/types/machineLearning/data/face.ts b/web/apps/photos/src/types/machineLearning/data/face.tsdeleted file mode 100644index cac391994f..0000000000--- a/web/apps/photos/src/types/machineLearning/data/face.ts+++ /dev/null@@ -1,27 +0,0 @@-/// [`x`] and [y] are the coordinates of the top left corner of the box, so the minimim values-/// [width] and [height] are the width and height of the box.-/// All values are in absolute pixels relative to the original image size.-export interface CenterBox {- x: number;- y: number;- height: number;- width: number;-}--export interface Point {- x: number;- y: number;-}--export interface Detection {- box: CenterBox;- landmarks: Point[];-}--export interface Face {- id: string;- confidence: number;- blur: number;- embedding: Float32Array;- detection: Detection;-}diff --git a/web/apps/photos/src/types/machineLearning/data/fileML.ts b/web/apps/photos/src/types/machineLearning/data/fileML.tsdeleted file mode 100644index 7835450e77..0000000000--- a/web/apps/photos/src/types/machineLearning/data/fileML.ts+++ /dev/null@@ -1,12 +0,0 @@-import { ClipEmbedding } from "./clip";-import { Face } from "./face";--export interface FileML {- fileID: number;- clip?: ClipEmbedding;- faces: Face[];- height: number;- width: number;- version: number;- error?: string;-}diff --git a/web/apps/photos/src/types/machineLearning/ui.ts b/web/apps/photos/src/types/machineLearning/ui.tsindex cd9f63f185..e69de29bb2 100644--- a/web/apps/photos/src/types/machineLearning/ui.ts+++ b/web/apps/photos/src/types/machineLearning/ui.ts@@ -1,7 +0,0 @@-export interface IndexStatus {- outOfSyncFilesExists: boolean;- nSyncedFiles: number;- nTotalFiles: number;- localFilesSynced: boolean;- peopleIndexSynced: boolean;-}diff --git a/web/apps/photos/src/types/search/index.ts b/web/apps/photos/src/types/search/index.tsindex cf50f4a060..7cff13298f 100644--- a/web/apps/photos/src/types/search/index.ts+++ b/web/apps/photos/src/types/search/index.ts@@ -1,9 +1,9 @@import { FILE_TYPE } from "@/media/file-type";import { City } from "services/locationSearchService";+import { Person } from "services/ml/types";import { LocationTagData } from "types/entity";import { EnteFile } from "types/file";-import { Person } from "types/machineLearning";-import { IndexStatus } from "types/machineLearning/ui";+import { IndexStatus } from "utils/storage/mlIDbStorage";export enum SuggestionType {DATE = "DATE",diff --git a/web/apps/photos/src/utils/image/index.ts b/web/apps/photos/src/utils/image/index.tsindex e4884716cd..38fe248c8b 100644--- a/web/apps/photos/src/utils/image/index.ts+++ b/web/apps/photos/src/utils/image/index.ts@@ -1,8 +1,8 @@// these utils only work in env where OffscreenCanvas is availableimport { Matrix, inverse } from "ml-matrix";+import { FaceAlignment } from "services/ml/types";import { BlobOptions, Dimensions } from "types/image";-import { FaceAlignment } from "types/machineLearning";import { enlargeBox } from "utils/machineLearning";import { Box } from "../../../thirdparty/face-api/classes";diff --git a/web/apps/photos/src/utils/machineLearning/config.ts b/web/apps/photos/src/utils/machineLearning/config.tsindex 0c25356aba..f47a96b055 100644--- a/web/apps/photos/src/utils/machineLearning/config.ts+++ b/web/apps/photos/src/utils/machineLearning/config.ts@@ -3,8 +3,8 @@ import {DEFAULT_ML_SYNC_CONFIG,DEFAULT_ML_SYNC_JOB_CONFIG,} from "constants/mlConfig";+import { MLSearchConfig, MLSyncConfig } from "services/ml/types";import { JobConfig } from "types/common/job";-import { MLSearchConfig, MLSyncConfig } from "types/machineLearning";import mlIDbStorage, {ML_SEARCH_CONFIG_NAME,ML_SYNC_CONFIG_NAME,diff --git a/web/apps/photos/src/utils/machineLearning/faceAlign.ts b/web/apps/photos/src/utils/machineLearning/faceAlign.tsindex beb98cea9a..620d3fff3c 100644--- a/web/apps/photos/src/utils/machineLearning/faceAlign.ts+++ b/web/apps/photos/src/utils/machineLearning/faceAlign.ts@@ -1,6 +1,6 @@import { Matrix } from "ml-matrix";+import { FaceAlignment, FaceDetection } from "services/ml/types";import { getSimilarityTransformation } from "similarity-transformation";-import { FaceAlignment, FaceDetection } from "types/machineLearning";import { Point } from "../../../thirdparty/face-api/classes";const ARCFACE_LANDMARKS = [diff --git a/web/apps/photos/src/utils/machineLearning/faceCrop.ts b/web/apps/photos/src/utils/machineLearning/faceCrop.tsindex d437a942dc..ef87f9f17d 100644--- a/web/apps/photos/src/utils/machineLearning/faceCrop.ts+++ b/web/apps/photos/src/utils/machineLearning/faceCrop.ts@@ -1,4 +1,4 @@-import { FaceAlignment, FaceCrop, FaceCropConfig } from "types/machineLearning";+import { FaceAlignment, FaceCrop, FaceCropConfig } from "services/ml/types";import { cropWithRotation } from "utils/image";import { enlargeBox } from ".";import { Box } from "../../../thirdparty/face-api/classes";diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.tsindex bc9ae39749..f2186399bf 100644--- a/web/apps/photos/src/utils/machineLearning/index.ts+++ b/web/apps/photos/src/utils/machineLearning/index.ts@@ -4,8 +4,6 @@ import log from "@/next/log";import PQueue from "p-queue";import DownloadManager from "services/download";import { getLocalFiles } from "services/fileService";-import { EnteFile } from "types/file";-import { Dimensions } from "types/image";import {DetectedFace,Face,@@ -13,7 +11,9 @@ import {MlFileData,Person,Versioned,-} from "types/machineLearning";+} from "services/ml/types";+import { EnteFile } from "types/file";+import { Dimensions } from "types/image";import { getRenderableImage } from "utils/file";import { clamp, warpAffineFloat32List } from "utils/image";import mlIDbStorage from "utils/storage/mlIDbStorage";diff --git a/web/apps/photos/src/utils/machineLearning/mldataMappers.ts b/web/apps/photos/src/utils/machineLearning/mldataMappers.tsindex fb91420aa8..1116448214 100644--- a/web/apps/photos/src/utils/machineLearning/mldataMappers.ts+++ b/web/apps/photos/src/utils/machineLearning/mldataMappers.ts@@ -1,10 +1,10 @@import {+ ClipEmbedding,Face,FaceDetection,Landmark,MlFileData,-} from "types/machineLearning";-import { ClipEmbedding } from "types/machineLearning/data/clip";+} from "services/ml/types";export interface FileML extends ServerFileMl {updatedAt: number;diff --git a/web/apps/photos/src/utils/storage/mlIDbStorage.ts b/web/apps/photos/src/utils/storage/mlIDbStorage.tsindex 766c3ac9a9..c90832df3d 100644--- a/web/apps/photos/src/utils/storage/mlIDbStorage.ts+++ b/web/apps/photos/src/utils/storage/mlIDbStorage.ts@@ -15,8 +15,15 @@ import {openDB,} from "idb";import isElectron from "is-electron";-import { Face, MLLibraryData, MlFileData, Person } from "types/machineLearning";-import { IndexStatus } from "types/machineLearning/ui";+import { Face, MLLibraryData, MlFileData, Person } from "services/ml/types";++export interface IndexStatus {+ outOfSyncFilesExists: boolean;+ nSyncedFiles: number;+ nTotalFiles: number;+ localFilesSynced: boolean;+ peopleIndexSynced: boolean;+}interface Config {}diff --git a/web/apps/photos/src/worker/ml.worker.ts b/web/apps/photos/src/worker/ml.worker.tsindex ed46b7bd44..aa650d4aff 100644--- a/web/apps/photos/src/worker/ml.worker.ts+++ b/web/apps/photos/src/worker/ml.worker.ts@@ -1,8 +1,8 @@import log from "@/next/log";import { expose } from "comlink";import mlService from "services/machineLearning/machineLearningService";+import { MachineLearningWorker } from "services/ml/types";import { EnteFile } from "types/file";-import { MachineLearningWorker } from "types/machineLearning";export class DedicatedMLWorker implements MachineLearningWorker {constructor() {