From 33ab6809e2aca13180deede254864b12affa4530 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 2 Jul 2024 15:31:24 +0530 Subject: [PATCH] Cleanup --- .../new/photos/services/ml/embedding.ts | 56 +++---------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/web/packages/new/photos/services/ml/embedding.ts b/web/packages/new/photos/services/ml/embedding.ts index e0bfa1af9a..79bdb2b0bb 100644 --- a/web/packages/new/photos/services/ml/embedding.ts +++ b/web/packages/new/photos/services/ml/embedding.ts @@ -242,33 +242,6 @@ const getEmbeddingsDiff = async ( if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`); return z.array(RemoteEmbedding).parse(await res.json()); }; -/* -export const putEmbedding = async ( - putEmbeddingReq: PutEmbeddingRequest, -): Promise => { - try { - const token = inWorker() - ? await workerBridge.getAuthToken() - : getToken(); - if (!token) { - log.info("putEmbedding failed: token not found"); - throw Error(CustomError.TOKEN_MISSING); - } - const resp = await HTTPService.put( - await apiURL("/embeddings"), - putEmbeddingReq, - null, - { - "X-Auth-Token": token, - }, - ); - return resp.data; - } catch (e) { - log.error("put embedding failed", e); - throw e; - } -}; -*/ /** * Upload an embedding to remote. @@ -298,32 +271,13 @@ export const putEmbedding = async ( method: "PUT", headers: await authenticatedRequestHeaders(), body: JSON.stringify({ + fileID: enteFile.id, + encryptedEmbedding: encryptedMetadataB64, + decryptionHeader: decryptionHeaderB64, model, }), }); if (!res.ok) throw new HTTPError(url, res); - - // Sanity check - - const rt = await decryptFileMetadata( - encryptedMetadataB64, - decryptionHeaderB64, - enteFile.key, - ); - console.log("put", embedding == rt); - - // const comlinkCryptoWorker = await ComlinkCryptoWorker.getInstance(); - // const { file: encryptedEmbeddingData } = - // await comlinkCryptoWorker.encryptMetadata(faceIndex, enteFile.key); - // // TODO(MR): Indexing - // console.log(encryptedEmbeddingData); - // throw new Error("Unimplemented"); - // await putEmbedding({ - // fileID: enteFile.id, - // encryptedEmbedding: encryptedEmbeddingData.encryptedData, - // decryptionHeader: encryptedEmbeddingData.decryptionHeader, - // model:, - // }); }; // MARK: - Face @@ -431,5 +385,9 @@ const FaceIndex = z // Retain fields we might not (currently) understand. .passthrough(); +/** + * Save the face index for the given {@link enteFile} on remote so that other + * clients can directly pull it instead of needing to reindex. + */ export const putFaceIndex = async (enteFile: EnteFile, faceIndex: FaceIndex) => putEmbedding(enteFile, "file-ml-clip-face", JSON.stringify(faceIndex));