π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Replace
Manav Rathi871cb417d632
diff --git a/web/apps/cast/src/services/livePhotoService.ts b/web/apps/cast/src/services/livePhotoService.tsdeleted file mode 100644index 789234bd3e..0000000000--- a/web/apps/cast/src/services/livePhotoService.ts+++ /dev/null@@ -1,32 +0,0 @@-import JSZip from "jszip";-import { EnteFile } from "types/file";-import {- getFileExtensionWithDot,- getFileNameWithoutExtension,-} from "utils/file";--class LivePhoto {- image: Uint8Array;- video: Uint8Array;- imageNameTitle: string;- videoNameTitle: string;-}--export const decodeLivePhoto = async (file: EnteFile, zipBlob: Blob) => {- const originalName = getFileNameWithoutExtension(file.metadata.title);- const zip = await JSZip.loadAsync(zipBlob, { createFolders: true });-- const livePhoto = new LivePhoto();- for (const zipFilename in zip.files) {- if (zipFilename.startsWith("image")) {- livePhoto.imageNameTitle =- originalName + getFileExtensionWithDot(zipFilename);- livePhoto.image = await zip.files[zipFilename].async("uint8array");- } else if (zipFilename.startsWith("video")) {- livePhoto.videoNameTitle =- originalName + getFileExtensionWithDot(zipFilename);- livePhoto.video = await zip.files[zipFilename].async("uint8array");- }- }- return livePhoto;-};diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.tsindex 7d62798823..37b228f607 100644--- a/web/apps/photos/src/services/export/index.ts+++ b/web/apps/photos/src/services/export/index.ts@@ -38,7 +38,7 @@ import { writeStream } from "utils/native-stream";import { getAllLocalCollections } from "../collectionService";import downloadManager from "../download";import { getAllLocalFiles } from "../fileService";-import { decodeLivePhoto } from "../livePhotoService";+import { decodeLivePhoto } from "@/media/live-photo";import { migrateExport } from "./migration";/** Name of the JSON file in which we keep the state of the export. */@@ -1017,7 +1017,7 @@ class ExportService {) {const electron = ensureElectron();const fileBlob = await new Response(fileStream).blob();- const livePhoto = await decodeLivePhoto(file, fileBlob);+ const livePhoto = await decodeLivePhoto(file.metadata.title, fileBlob);const imageExportName = await safeFileName(collectionExportPath,livePhoto.imageNameTitle,diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.tsindex b90c12e1c2..8591437e2b 100644--- a/web/apps/photos/src/services/export/migration.ts+++ b/web/apps/photos/src/services/export/migration.ts@@ -1,3 +1,4 @@+import { decodeLivePhoto } from "@/media/live-photo";import { ensureElectron } from "@/next/electron";import log from "@/next/log";import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";@@ -7,7 +8,6 @@ import { FILE_TYPE } from "constants/file";import { getLocalCollections } from "services/collectionService";import downloadManager from "services/download";import { getAllLocalFiles } from "services/fileService";-import { decodeLivePhoto } from "services/livePhotoService";import { Collection } from "types/collection";import {CollectionExportNames,@@ -318,7 +318,10 @@ async function getFileExportNamesFromExportedFiles(if (file.metadata.fileType === FILE_TYPE.LIVE_PHOTO) {const fileStream = await downloadManager.getFile(file);const fileBlob = await new Response(fileStream).blob();- const livePhoto = await decodeLivePhoto(file, fileBlob);+ const livePhoto = await decodeLivePhoto(+ file.metadata.title,+ fileBlob,+ );const imageExportName = getUniqueFileExportNameForMigration(collectionPath,livePhoto.imageNameTitle,diff --git a/web/apps/photos/src/services/livePhotoService.ts b/web/apps/photos/src/services/livePhotoService.tsdeleted file mode 100644index a4fa32de82..0000000000--- a/web/apps/photos/src/services/livePhotoService.ts+++ /dev/null@@ -1,48 +0,0 @@-import JSZip from "jszip";-import { EnteFile } from "types/file";-import {- getFileExtensionWithDot,- getFileNameWithoutExtension,-} from "utils/file";--/**- * An in-memory representation of a live photo- */-class LivePhoto {- image: Uint8Array;- video: Uint8Array;- imageNameTitle: string;- videoNameTitle: string;-}--export const decodeLivePhoto = async (file: EnteFile, zipBlob: Blob) => {- const originalName = getFileNameWithoutExtension(file.metadata.title);- const zip = await JSZip.loadAsync(zipBlob, { createFolders: true });-- const livePhoto = new LivePhoto();- for (const zipFilename in zip.files) {- if (zipFilename.startsWith("image")) {- livePhoto.imageNameTitle =- originalName + getFileExtensionWithDot(zipFilename);- livePhoto.image = await zip.files[zipFilename].async("uint8array");- } else if (zipFilename.startsWith("video")) {- livePhoto.videoNameTitle =- originalName + getFileExtensionWithDot(zipFilename);- livePhoto.video = await zip.files[zipFilename].async("uint8array");- }- }- return livePhoto;-};--export const encodeLivePhoto = async (livePhoto: LivePhoto) => {- const zip = new JSZip();- zip.file(- "image" + getFileExtensionWithDot(livePhoto.imageNameTitle),- livePhoto.image,- );- zip.file(- "video" + getFileExtensionWithDot(livePhoto.videoNameTitle),- livePhoto.video,- );- return await zip.generateAsync({ type: "uint8array" });-};diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.tsindex 2c199981a1..6a5984a4c9 100644--- a/web/apps/photos/src/utils/machineLearning/index.ts+++ b/web/apps/photos/src/utils/machineLearning/index.ts@@ -1,9 +1,9 @@+import { decodeLivePhoto } from "@/media/live-photo";import log from "@/next/log";import { FILE_TYPE } from "constants/file";import PQueue from "p-queue";import DownloadManager from "services/download";import { getLocalFiles } from "services/fileService";-import { decodeLivePhoto } from "services/livePhotoService";import { EnteFile } from "types/file";import { Dimensions } from "types/image";import {@@ -134,7 +134,7 @@ async function getOriginalConvertedFile(file: EnteFile, queue?: PQueue) {if (file.metadata.fileType === FILE_TYPE.IMAGE) {return await getRenderableImage(file.metadata.title, fileBlob);} else {- const livePhoto = await decodeLivePhoto(file, fileBlob);+ const livePhoto = await decodeLivePhoto(file.metadata.title, fileBlob);return await getRenderableImage(livePhoto.imageNameTitle,new Blob([livePhoto.image]),