Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Web enum cleanup

Manav Rathi1214b4ddc385
diff --git a/web/apps/photos/src/services/clip-service.ts b/web/apps/photos/src/services/clip-service.ts
index 4df9e5728d..c6a94213fb 100644
--- a/web/apps/photos/src/services/clip-service.ts
+++ b/web/apps/photos/src/services/clip-service.ts
@@ -8,7 +8,7 @@ import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import { FILE_TYPE } from "constants/file";
import isElectron from "is-electron";
import PQueue from "p-queue";
-import { Embedding, Model } from "types/embedding";
+import { Embedding } from "types/embedding";
import { EnteFile } from "types/file";
import { getPersonalFiles } from "utils/file";
import downloadManager from "./download";
@@ -339,12 +339,11 @@ class CLIPService {
log.info(
`putting clip embedding to server for file: ${file.metadata.title} fileID: ${file.id}`,
);
- const model = Model.ONNX_CLIP;
await putEmbedding({
fileID: file.id,
encryptedEmbedding: encryptedEmbeddingData.encryptedData,
decryptionHeader: encryptedEmbeddingData.decryptionHeader,
- model,
+ model: "onnx-clip",
});
};
diff --git a/web/apps/photos/src/services/embeddingService.ts b/web/apps/photos/src/services/embeddingService.ts
index 79fa5ef7ea..c4c0075c69 100644
--- a/web/apps/photos/src/services/embeddingService.ts
+++ b/web/apps/photos/src/services/embeddingService.ts
@@ -5,11 +5,11 @@ import HTTPService from "@ente/shared/network/HTTPService";
import { getEndpoint } from "@ente/shared/network/api";
import localForage from "@ente/shared/storage/localForage";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
-import {
+import type {
Embedding,
+ EmbeddingModel,
EncryptedEmbedding,
GetEmbeddingDiffResponse,
- Model,
PutEmbeddingRequest,
} from "types/embedding";
import { EnteFile } from "types/file";
@@ -40,10 +40,10 @@ export const getAllLocalEmbeddings = async () => {
export const getLocalEmbeddings = async () => {
const embeddings = await getAllLocalEmbeddings();
- return embeddings.filter((embedding) => embedding.model === Model.ONNX_CLIP);
+ return embeddings.filter((embedding) => embedding.model === "onnx-clip");
};
-const getModelEmbeddingSyncTime = async (model: Model) => {
+const getModelEmbeddingSyncTime = async (model: EmbeddingModel) => {
return (
(await localForage.getItem<number>(
`${model}-${EMBEDDING_SYNC_TIME_TABLE}`,
@@ -51,11 +51,15 @@ const getModelEmbeddingSyncTime = async (model: Model) => {
);
};
-const setModelEmbeddingSyncTime = async (model: Model, time: number) => {
+const setModelEmbeddingSyncTime = async (
+ model: EmbeddingModel,
+ time: number,
+) => {
await localForage.setItem(`${model}-${EMBEDDING_SYNC_TIME_TABLE}`, time);
};
-export const syncEmbeddings = async (models: Model[] = [Model.ONNX_CLIP]) => {
+export const syncEmbeddings = async () => {
+ const models: EmbeddingModel[] = ["onnx-clip"];
try {
let allEmbeddings = await getAllLocalEmbeddings();
const localFiles = await getAllLocalFiles();
@@ -138,7 +142,7 @@ export const syncEmbeddings = async (models: Model[] = [Model.ONNX_CLIP]) => {
export const getEmbeddingsDiff = async (
sinceTime: number,
- model: Model,
+ model: EmbeddingModel,
): Promise<GetEmbeddingDiffResponse> => {
try {
const token = getToken();
diff --git a/web/apps/photos/src/types/embedding.tsx b/web/apps/photos/src/types/embedding.tsx
index b618ed3159..c0014d01e8 100644
--- a/web/apps/photos/src/types/embedding.tsx
+++ b/web/apps/photos/src/types/embedding.tsx
@@ -1,10 +1,16 @@
-export enum Model {
- ONNX_CLIP = "onnx-clip",
-}
+/**
+ * The embeddings models that we support.
+ *
+ * This is an exhaustive set of values we pass when PUT-ting encrypted
+ * embeddings on the server. However, we should be prepared to receive an
+ * {@link EncryptedEmbedding} with a model value distinct from one of these.
+ */
+export type EmbeddingModel = "onnx-clip";
export interface EncryptedEmbedding {
fileID: number;
- model: Model;
+ /** @see {@link EmbeddingModel} */
+ model: string;
encryptedEmbedding: string;
decryptionHeader: string;
updatedAt: number;
@@ -24,7 +30,7 @@ export interface GetEmbeddingDiffResponse {
export interface PutEmbeddingRequest {
fileID: number;
- model: Model;
+ model: EmbeddingModel;
encryptedEmbedding: string;
decryptionHeader: string;
}