π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Trace
Manav Rathib121daa607f6
diff --git a/web/packages/new/photos/services/exif.ts b/web/packages/new/photos/services/exif.tsindex e3bc7a221a..ee41a0127c 100644--- a/web/packages/new/photos/services/exif.ts+++ b/web/packages/new/photos/services/exif.ts@@ -6,31 +6,62 @@ import {type ParsedMetadataDate,} from "@/media/file-metadata";import ExifReader from "exifreader";+import type { EnteFile } from "../types/file";import type { ParsedExtractedMetadata } from "../types/metadata";import { isInternalUser } from "./feature-flags";// TODO: Exif: WIP flag to inspect the migration from old to new lib.export const wipNewLib = async () => isDevBuild && (await isInternalUser());+const cmpTsEq = (a: number | undefined | null, b: number | undefined) => {+ if (!a || !b) return false;+ if (a == b) return true;+ if (a / 1e6 == b / 1e6) return true;+ return false;+};+export const cmpNewLib = (oldLib: ParsedExtractedMetadata,newLib: ParsedMetadata,) => {+ const logM = (r: string) =>+ log.info("[exif]", r, JSON.stringify({ old: oldLib, new: newLib }));if (- oldLib.creationTime == newLib.creationDate?.timestamp &&+ cmpTsEq(oldLib.creationTime, newLib.creationDate?.timestamp) &&oldLib.location.latitude == newLib.location?.latitude &&oldLib.location.longitude == newLib.location?.longitude) {- if (oldLib.width == newLib.width && oldLib.height == newLib.height)- log.info("Exif migration β ");- else log.info("Exif migration β β¨");+ if (+ oldLib.width == newLib.width &&+ oldLib.height == newLib.height &&+ oldLib.creationTime == newLib.creationDate?.timestamp+ )+ logM("exact match");+ else logM("enhanced match");log.debug(() => ["exif/cmp", { oldLib, newLib }]);} else {- log.info("Exif migration - Potential mismatch βοΈπ©");- log.info({ oldLib, newLib });+ logM("potential mismatch βοΈπ©");}};+export const cmpNewLib2 = (enteFile: EnteFile, _exif: unknown) => {+ // cast is fine here, this is just temporary debugging code.+ const rawExif = _exif as RawExifTags;+ const newLib = parseExif(rawExif);+ const pem = {+ location: {+ latitude: enteFile.metadata.latitude,+ longitude: enteFile.metadata.longitude,+ },+ creationTime: enteFile.metadata.creationTime,+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing+ width: enteFile.w || null,+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing+ height: enteFile.h || null,+ };+ cmpNewLib(pem, newLib);+};+/*** Extract Exif and other metadata from the given file.*diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.tsindex e425f03911..015dc7462d 100644--- a/web/packages/new/photos/services/ml/blob.ts+++ b/web/packages/new/photos/services/ml/blob.ts@@ -22,7 +22,7 @@ export interface IndexableBlobs {* - For live photos it will the (original) image component of the live* photo.*/- originalBlob: Blob | undefined;+ originalImageBlob: Blob | undefined;/*** The original (if the browser possibly supports rendering this type of* images) or otherwise a converted JPEG blob.@@ -121,19 +121,19 @@ const indexableUploadItemBlobs = async (electron: MLWorkerElectron,) => {const fileType = enteFile.metadata.fileType;- let originalBlob: Blob | undefined;+ let originalImageBlob: Blob | undefined;let renderableBlob: Blob;if (fileType == FileType.video) {const thumbnailData = await DownloadManager.getThumbnail(enteFile);renderableBlob = new Blob([ensure(thumbnailData)]);} else {- originalBlob = await readNonVideoUploadItem(uploadItem, electron);+ originalImageBlob = await readNonVideoUploadItem(uploadItem, electron);renderableBlob = await renderableImageBlob(enteFile.metadata.title,- originalBlob,+ originalImageBlob,);}- return { originalBlob, renderableBlob };+ return { originalImageBlob, renderableBlob };};/**@@ -185,19 +185,19 @@ export const indexableEnteFileBlobs = async (if (fileType == FileType.video) {const thumbnailData = await DownloadManager.getThumbnail(enteFile);return {- originalBlob: undefined,+ originalImageBlob: undefined,renderableBlob: new Blob([ensure(thumbnailData)]),};}const fileStream = await DownloadManager.getFile(enteFile);- const originalBlob = await new Response(fileStream).blob();+ const originalImageBlob = await new Response(fileStream).blob();let renderableBlob: Blob;if (fileType == FileType.livePhoto) {const { imageFileName, imageData } = await decodeLivePhoto(enteFile.metadata.title,- originalBlob,+ originalImageBlob,);renderableBlob = await renderableImageBlob(imageFileName,@@ -206,12 +206,12 @@ export const indexableEnteFileBlobs = async (} else if (fileType == FileType.image) {renderableBlob = await renderableImageBlob(enteFile.metadata.title,- originalBlob,+ originalImageBlob,);} else {// A layer above us should've already filtered these out.throw new Error(`Cannot index unsupported file type ${fileType}`);}- return { originalBlob, renderableBlob };+ return { originalImageBlob, renderableBlob };};diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex d19c4e221d..9070536da5 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -9,7 +9,7 @@ import { ensure } from "@/utils/ensure";import { wait } from "@/utils/promise";import { expose } from "comlink";import downloadManager from "../download";-import { extractRawExif } from "../exif";+import { cmpNewLib2, extractRawExif } from "../exif";import { getAllLocalFiles, getLocalTrashedFiles } from "../files";import type { UploadItem } from "../upload/types";import {@@ -410,7 +410,8 @@ const index = async (// There is at least one derived data type that still needs to be indexed.- const { originalBlob, renderableBlob } = await indexableBlobs(+ // Videos will not have an original blob whilst having a renderable blob.+ const { originalImageBlob, renderableBlob } = await indexableBlobs(enteFile,uploadItem,electron,@@ -443,7 +444,9 @@ const index = async (existingFaceIndex ?? indexFaces(enteFile, image, electron),existingCLIPIndex ?? indexCLIP(image, electron),existingExif ??- (originalBlob ? extractRawExif(originalBlob) : undefined),+ (originalImageBlob+ ? extractRawExif(originalImageBlob)+ : undefined),]);} catch (e) {// See: [Note: Transient and permanent indexing failures]@@ -452,12 +455,14 @@ const index = async (throw e;}+ if (originalImageBlob) cmpNewLib2(enteFile, exif);+log.debug(() => {const ms = Date.now() - startTime;const msg = [];if (!existingFaceIndex) msg.push(`${faceIndex.faces.length} faces`);if (!existingCLIPIndex) msg.push("clip");- if (!hasExistingExif && originalBlob) msg.push("exif");+ if (!hasExistingExif && originalImageBlob) msg.push("exif");return `Indexed ${msg.join(" and ")} in ${f} (${ms} ms)`;});