π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
More
Manav Rathiff1c20288f53
diff --git a/web/packages/new/photos/services/file-data.ts b/web/packages/new/photos/services/file-data.tsindex 8e5d5f8d4c..2478436f35 100644--- a/web/packages/new/photos/services/file-data.ts+++ b/web/packages/new/photos/services/file-data.ts@@ -5,36 +5,29 @@ import type { EnteFile } from "@/new/photos/types/file";import { z } from "zod";/**- * [Note: Derived embeddings model]+ * [Note: File data APIs]*- * The API endpoints related to embeddings and are parameterized by a "model"- * enum. This is a bit of misnomer, since the contents of the payload are not- * just the raw embeddings themselves, but also additional data generated by the- * ML model.+ * Remote provides some APIs that talk in terms of "file data", which refers to+ * all the files (original or derived) associated with an {@link EnteFile}.*- * For example, the face indexing process generates multiple face embeddings per- * file, each with an associated detection box. So instead of storing just a- * singular embedding, the data is an entire face index structure containing- * multiple embeddings and associated data.+ * For example, for each original image that the user uploads, there will be an+ * associated thumbnail file, potentially one or more preview files (optimized+ * for size or compatibility across devices), various ML embeddings generated+ * for that file, and possibly more such files in the future.*- * Further down, it was realized that the fan out caused on remote when trying- * to fetch both CLIP and face embeddings was problematic, and also that their- * raw JSON was unnecessarily big. To deal with these better, we now have a- * single "derived" model type, whose data is a gzipped map of the form:- *- * {- * "face": ... the face indexing result ...- * "clip": ... the CLIP indexing result ...- * ... more in the future ...- * }+ * There are specialized APIs for fetching and uploading the originals and the+ * thumbnails. But for the other associated data, we can use the file data APIs.*/type FileDataType = "mldata";const RemoteFileData = z.object({- /** The ID of the file whose embedding this is. */+ /**+ * The ID of the {@link EnteFile} with which this file data is associated.+ */fileID: z.number(),/**- * Base64 representation of the encrypted (model specific) embedding JSON.+ * Base64 representation of the encrypted data. Its plaintext contents will+ * be specific to each file data type.*/encryptedData: z.string(),/**@@ -48,29 +41,34 @@ const RemoteFileData = z.object({type RemoteFileData = z.infer<typeof RemoteFileData>;/**- * Fetch {@link model} embeddings for the given list of files.+ * Fetch file data of a particular type for the given list of files.+ *+ * @param type The {@link FileDataType} which we want.*- * @param model The {@link FileDataType} which we want.+ * @param fileIDs The ids of the files for which we want the file data.*- * @param fileIDs The ids of the files for which we want the embeddings.+ * @returns a list of {@link RemoteFileData} items for the files which had file+ * data for the given type, and that remote was able to successfully retrieve.*- * @returns a list of {@link RemoteFileData} for the files which had embeddings- * (and that remote was able to successfully retrieve). The order of this list- * is arbitrary, and the caller should use the {@link fileID} present within the- * {@link RemoteFileData} to associate an item in the result back to a file- * instead of relying on the order or count of items in the result.+ * The order of this list is arbitrary, and the caller should use the+ * {@link fileID} present within the {@link RemoteFileData} to associate an item+ * in the result back to a file instead of relying on the order or count of+ * items in the result.+ *+ * In rare cases (issues with the upstream object storage), it is possible for+ * remote to not return entries for a particular file even though it has+ * associated data of that type. Such skipped entries are mentioned in the+ * payload, but we don't parse that information currently since the higher+ * levels of our code that use this function handle such rare skips gracefully.*/export const fetchFileData = async (- model: FileDataType,+ type: FileDataType,fileIDs: number[],): Promise<RemoteFileData[]> => {const res = await fetch(await apiURL("/files/data/fetch"), {method: "POST",headers: await authenticatedRequestHeaders(),- body: JSON.stringify({- type: "mldata",- fileIDs,- }),+ body: JSON.stringify({ type, fileIDs }),});ensureOk(res);return z.object({ data: z.array(RemoteFileData) }).parse(await res.json())