π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip scaffold
Manav Rathi41851c97be7d
diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.tsindex 4461cc761d..b1a8ba2c60 100644--- a/web/packages/new/photos/services/ml/blob.ts+++ b/web/packages/new/photos/services/ml/blob.ts@@ -9,11 +9,62 @@ import DownloadManager from "../download";import type { UploadItem } from "../upload/types";import type { MLWorkerElectron } from "./worker-types";+/**+ * A data structure containing data about an image in all formats that the+ * various indexing steps need. Consolidating all the data here and parsing them+ * in one go obviates the need for each indexing step to roll their own parsing.+ */export interface IndexableImage {+ /**+ * The original file's data, and a renderable representation of it (both as+ * {@link Blob}s).+ */+ blobs: IndexableBlobs;+ /**+ * An {@link ImageBitmap} from the original or converted image.+ *+ * This bitmap is constructed from the original file's data if the+ * browser knows how to handle it; otherwise we first convert it to a JPEG+ * and then create the bitmap from that.+ */bitmap: ImageBitmap;+ /**+ * The RGBA {@link ImageData} of the {@link bitmap}, obtained by rendering+ * it to an offscreen canvas.+ */data: ImageData;}+/**+ * A pair of blobs - the original, and a possibly converted "renderable" one -+ * for a file that we're trying to index.+ */+export interface IndexableBlobs {+ /**+ * The original file's data (as a {@link Blob}).+ *+ * - For images this is guaranteed to be present.+ * - For videos it will not be present.+ * - For live photos it will the (original) image component of the live+ * photo.+ */+ original: Blob | undefined;+ /**+ * The original (if the browser possibly supports rendering this type of+ * images) or otherwise a converted JPEG blob.+ *+ * This blob is meant to be used to construct the {@link ImageBitmap}+ * that'll be used for further operations that need access to the RGB data+ * of the image.+ *+ * - For images this is constructed from the image.+ * - For videos this is constructed from the thumbnail.+ * - For live photos this is constructed from the image component of the+ * live photo.+ */+ renderable: Blob;+}+/*** Create an {@link ImageBitmap} from the given {@link imageBlob}, and return* both the image bitmap and its {@link ImageData}.@@ -60,19 +111,7 @@ export const renderableBlob = async (): Promise<Blob> =>uploadItem? await renderableUploadItemBlob(enteFile, uploadItem, electron)- : await renderableEnteFileBlob(enteFile);--export const renderableEnteFileBlob = async (enteFile: EnteFile) => {- const fileType = enteFile.metadata.fileType;- let blob: Blob | undefined;- if (fileType == FILE_TYPE.VIDEO) {- const thumbnailData = await DownloadManager.getThumbnail(enteFile);- blob = new Blob([ensure(thumbnailData)]);- } else {- blob = await fetchRenderableBlob(enteFile);- }- return ensure(blob);-};+ : await indexableBlobs(enteFile);const renderableUploadItemBlob = async (enteFile: EnteFile,@@ -126,20 +165,42 @@ const readNonVideoUploadItem = async (}};-const fetchRenderableBlob = async (enteFile: EnteFile) => {+/**+ * Return a pair of blobs for the given file - the original, and a renderable+ * one (possibly involving a JPEG conversion).+ */+export const indexableBlobs = async (+ enteFile: EnteFile,+): Promise<IndexableBlobs> => {+ const fileType = enteFile.metadata.fileType;+ if (fileType == FILE_TYPE.VIDEO) {+ const thumbnailData = await DownloadManager.getThumbnail(enteFile);+ return {+ original: undefined,+ renderable: new Blob([ensure(thumbnailData)]),+ };+ }+const fileStream = await DownloadManager.getFile(enteFile);const fileBlob = await new Response(fileStream).blob();- const fileType = enteFile.metadata.fileType;- if (fileType == FILE_TYPE.IMAGE) {- return renderableImageBlob(enteFile.metadata.title, fileBlob);- } else if (fileType == FILE_TYPE.LIVE_PHOTO) {+ let blob: Blob | undefined;+ if (fileType == FILE_TYPE.LIVE_PHOTO) {const { imageFileName, imageData } = await decodeLivePhoto(enteFile.metadata.title,fileBlob,);- return renderableImageBlob(imageFileName, new Blob([imageData]));+ blob = await renderableImageBlob(imageFileName, new Blob([imageData]));+ } else if (fileType == FILE_TYPE.IMAGE) {+ blob = await renderableImageBlob(enteFile.metadata.title, fileBlob);} else {// A layer above us should've already filtered these out.throw new Error(`Cannot index unsupported file type ${fileType}`);}++ if (!blob)+ throw new++ }++ return { original: fileBlob, renderable: ensure(blob) };};diff --git a/web/packages/new/photos/services/ml/crop.ts b/web/packages/new/photos/services/ml/crop.tsindex 04fe0f09f6..c988c24b92 100644--- a/web/packages/new/photos/services/ml/crop.ts+++ b/web/packages/new/photos/services/ml/crop.ts@@ -1,7 +1,7 @@import { blobCache } from "@/base/blob-cache";import { ensure } from "@/utils/ensure";import type { EnteFile } from "../../types/file";-import { renderableEnteFileBlob } from "./blob";+import { indexableBlobs } from "./blob";import { type Box, type FaceIndex } from "./face";import { clamp } from "./math";@@ -26,9 +26,7 @@ export const regenerateFaceCrops = async (enteFile: EnteFile,faceIndex: FaceIndex,) => {- const imageBitmap = await createImageBitmap(- await renderableEnteFileBlob(enteFile),- );+ const imageBitmap = await createImageBitmap(await indexableBlobs(enteFile));try {await saveFaceCrops(imageBitmap, faceIndex);