Web enum cleanup

This commit is contained in:
Manav Rathi 2024-04-09 21:12:00 +05:30
parent a813de5617
commit 1214b4ddc3
No known key found for this signature in database
3 changed files with 24 additions and 15 deletions

View file

@ -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",
});
};

View file

@ -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();

View file

@ -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;
}