π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
rework 3
Manav Rathib5130f1ab647
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.tsindex 05c6c7bdff..29b239be0f 100644--- a/web/packages/gallery/components/viewer/data-source.ts+++ b/web/packages/gallery/components/viewer/data-source.ts@@ -423,15 +423,15 @@ const enqueueUpdates = async (file: EnteFile) => {switch (sourceURLs.type) {case "image": {- const imageURL = sourceURLs.renderableImageURL;- const originalImageBlob = sourceURLs.originalImageBlob;+ const { imageURL, originalImageBlob } = sourceURLs;const itemData = await withDimensionsIfPossible(imageURL);update({ ...itemData, imageURL, originalImageBlob });break;}case "video": {- update({ videoURL: sourceURLs.playableVideoURL });+ const { videoURL } = sourceURLs;+ update({ videoURL });break;}@@ -445,14 +445,14 @@ const enqueueUpdates = async (file: EnteFile) => {//// For these reasons, we resolve with the video first, then// resolve with the image.- const videoURL = await sourceURLs.video();+ const videoURL = await sourceURLs.videoURL();update({videoURL,isContentLoading: true,isContentZoomable: false,});- const imageURL = await sourceURLs.image();- const originalImageBlob = sourceURLs.originalImageBlob()!;+ const imageURL = await sourceURLs.imageURL();+ const originalImageBlob = sourceURLs.originalImageBlob;update({...(await withDimensionsIfPossible(imageURL)),imageURL,diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.tsindex 6c31a1e11f..92835021d9 100644--- a/web/packages/gallery/services/download.ts+++ b/web/packages/gallery/services/download.ts@@ -16,7 +16,7 @@ import { ensureAuthToken } from "ente-base/local-user";import log from "ente-base/log";import { customAPIOrigin } from "ente-base/origins";import {- playableVideoBlob,+ playableVideoURL,renderableImageBlob,} from "ente-gallery/utils/convert";import type { EnteFile } from "ente-media/file";@@ -47,7 +47,7 @@ export type RenderableSourceURLs =* {@link originalImageBlob}. In other cases, this will point to a* separate, converted blob.*/- renderableImageURL: string;+ imageURL: string;/*** A {@link Blob} from the original image.*@@ -74,28 +74,26 @@ export type RenderableSourceURLs =* This is a best effort basis. Not all videos will be playable in all* browsers, so the file might still not be previewable.*/- playableVideoURL: string;+ videoURL: string;}| {type: "livePhoto";/**- * Similar to the {@link renderableImageURL} for type "image", except+ * Similar to the {@link imageURL} for type "image", except* as a promise since we might want to operate on the different* components of a live image in a staggered order.*/- renderableImageURL: () => Promise<string>;+ imageURL: () => Promise<string>;/**- * Similar to the {@link originalImageBlob} for type "image", except- * as a getter since we might want to operate on the different- * components of a live image in a staggered order.+ * Similar to the {@link originalImageBlob} for type "image".*/- originalImageBlob: () => Blob;+ originalImageBlob: Blob;/**- * Similar to the {@link playableVideoURL} for type "video", except as+ * Similar to the {@link videoURL} for type "video", except as* a promise since we might want to operate on the different* components of a live image in a staggered order.*/- playableVideoURL: () => Promise<string>;+ videoURL: () => Promise<string>;};/**@@ -605,77 +603,47 @@ const createRenderableSourceURLs = async (): Promise<RenderableSourceURLs> => {const originalFileURL = await originalFileURLPromise;const fileBlob = await fetch(originalFileURL).then((res) => res.blob());-- const existingOrNewObjectURL = (convertedBlob: Blob | null | undefined) =>- !convertedBlob || convertedBlob === fileBlob- ? originalFileURL- : URL.createObjectURL(convertedBlob);-const fileName = file.metadata.title;const fileType = file.metadata.fileType;+switch (fileType) {case FileType.image: {const convertedBlob = await renderableImageBlob(fileBlob, fileName);- const renderableImageURL = existingOrNewObjectURL(convertedBlob);+ const imageURL =+ convertedBlob === fileBlob+ ? originalFileURL+ : URL.createObjectURL(convertedBlob);const originalImageBlob = fileBlob;const mimeType = convertedBlob.type;- return {- type: "image",- renderableImageURL,- originalImageBlob,- mimeType,- };+ return { type: "image", imageURL, originalImageBlob, mimeType };}- case FileType.livePhoto: {- const livePhoto = await decodeLivePhoto(- file.metadata.title,- fileBlob,- );- const getRenderableLivePhotoImageURL = async () => {- try {- const imageBlob = new Blob([livePhoto.imageData]);- return URL.createObjectURL(- await renderableImageBlob(- imageBlob,- livePhoto.imageFileName,- ),- );- } catch {- //ignore and return null- return undefined;- }- };-- const getOriginalImageBlob = () => {- return new Blob([livePhoto.imageData]);- };+ case FileType.livePhoto: {+ const livePhoto = await decodeLivePhoto(fileName, fileBlob);+ const originalImageBlob = new Blob([livePhoto.imageData]);++ const imageURL = async () =>+ URL.createObjectURL(+ await renderableImageBlob(+ originalImageBlob,+ livePhoto.imageFileName,+ ),+ );- const getRenderableLivePhotoVideoURL = async () => {- const videoBlob = new Blob([livePhoto.videoData]);- const convertedVideoBlob = await playableVideoBlob(+ const videoURL = () =>+ playableVideoURL(livePhoto.videoFileName,- videoBlob,+ new Blob([livePhoto.videoData]),);- if (!convertedVideoBlob) return undefined;- return URL.createObjectURL(convertedVideoBlob);- };-- return {- type: "livePhoto",- image: getRenderableLivePhotoImageURL,- originalImageBlob: getOriginalImageBlob,- video: getRenderableLivePhotoVideoURL,- };++ return { type: "livePhoto", imageURL, originalImageBlob, videoURL };}case FileType.video: {- const convertedBlob = await playableVideoBlob(fileName, fileBlob);- const convertedURL = existingOrNewObjectURL(convertedBlob);- // TODO:- const url = convertedURL!;- return { type: "video", playableVideoURL: url };+ const videoURL = await playableVideoURL(fileName, fileBlob);+ return { type: "video", videoURL };}+default: {throw new Error(`Unsupported file type ${fileType}`);}diff --git a/web/packages/gallery/utils/convert.ts b/web/packages/gallery/utils/convert.tsindex 956234c7a7..4f1ecd4051 100644--- a/web/packages/gallery/utils/convert.ts+++ b/web/packages/gallery/utils/convert.ts@@ -40,7 +40,7 @@ import { detectFileTypeInfo } from "./detect-type";export const renderableImageBlob = async (imageBlob: Blob,fileName: string,-) => {+): Promise<Blob> => {try {const file = new File([imageBlob], fileName);const fileTypeInfo = await detectFileTypeInfo(file);@@ -157,46 +157,55 @@ const testHEICDataURL ="data:image/heic;base64,AAAAGGZ0eXBoZWljAAAAAG1pZjFoZWljAAABaW1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAHBpY3QAAAAAAAAAAAAAAAAAAAAADnBpdG0AAAAAAAEAAAAiaWxvYwAAAABEQAABAAEAAAAAAYkAAQAAAAAAAAAuAAAAI2lpbmYAAAAAAAEAAAAVaW5mZQIAAAAAAQAAaHZjMQAAAADpaXBycAAAAMppcGNvAAAAdmh2Y0MBA3AAAAAAAAAAAAAe8AD8/fj4AAAPAyAAAQAYQAEMAf//A3AAAAMAkAAAAwAAAwAeugJAIQABACpCAQEDcAAAAwCQAAADAAADAB6gIIEFluqumubgIaDAgAAAAwCAAAADAIQiAAEABkQBwXPBiQAAABRpc3BlAAAAAAAAAEAAAABAAAAAKGNsYXAAAAABAAAAAQAAAAEAAAAB////wQAAAAL////BAAAAAgAAABBwaXhpAAAAAAMICAgAAAAXaXBtYQAAAAAAAAABAAEEgQKDBAAAADZtZGF0AAAAKigBrwayEx2gkim3i/2Rd0CR/V6h6GbEyV3dheegYfLV9ZwraCH8nff+7w==";/**- * Return a new {@link Blob} containing a video's data in a format that the- * browser (likely) knows how to play back (using an video tag).+ * Return a object URL containing a video's data in a format that the browser+ * (likely) knows how to play back using an video tag.** Unlike {@link renderableImageBlob}, this uses a much simpler flowchart:*- * - If the browser thinks it can play the video, then return the original blob- * back.+ * 1. If the browser thinks it can play the video, then return the an object URL+ * created by directly using the provided {@link videoBlob}.*- * - Otherwise try to convert using FFmpeg. This conversion always happens on- * the desktop app, but in the browser the conversion only happens for short- * videos since the Wasm FFmpeg implementation is much slower.+ * 2. Otherwise try to convert using FFmpeg. This conversion always happens on+ * the desktop app, but in the browser the conversion only happens for short+ * videos since the Wasm FFmpeg implementation is much slower.*- * - On errors, return the original.+ * 3. On errors, return the original (as would've happened for step 1).*/-export const playableVideoBlob = async (fileName: string, videoBlob: Blob) => {- const converted = async () => {+export const playableVideoURL = async (+ fileName: string,+ videoBlob: Blob,+): Promise<string> => {+ const videoObjectURL = URL.createObjectURL(videoBlob);+ const isPlayable = await isPlaybackPossible(videoObjectURL);++ let shouldConvert = false;++ if (!isPlayable) {+ // The browser doesn't think it can play this video, try transcoding.+ if (isDesktop) {+ // Always on desktop.+ shouldConvert = true;+ } else {+ // Don't try to transcode on the web if the file is too big.+ if (videoBlob.size < 100 * 1024 * 1024 /* 100 MB, arbitrary */) {+ shouldConvert = true;+ }+ }+ }++ if (shouldConvert) {try {log.info(`Converting ${fileName} to mp4`);const convertedBlob = await convertToMP4(videoBlob);- return new Blob([convertedBlob], { type: "video/mp4" });+ return URL.createObjectURL(+ new Blob([convertedBlob], { type: "video/mp4" }),+ );} catch (e) {log.error(`Video conversion failed for ${fileName}`, e);- return videoBlob;- }- };-- const isPlayable = await isPlaybackPossible(URL.createObjectURL(videoBlob));- if (isPlayable) return videoBlob;-- // The browser doesn't think it can play this video, try transcoding.- if (isDesktop) {- return converted();- } else {- // Don't try to transcode on the web if the file is too big.- if (videoBlob.size > 100 * 1024 * 1024 /* 100 MB, arbitrary */) {- return null;- } else {- return converted();}}++ return videoObjectURL;};/**diff --git a/web/packages/new/photos/components/ImageEditorOverlay.tsx b/web/packages/new/photos/components/ImageEditorOverlay.tsxindex 4555e977fa..c19d23f750 100644--- a/web/packages/new/photos/components/ImageEditorOverlay.tsx+++ b/web/packages/new/photos/components/ImageEditorOverlay.tsx@@ -383,8 +383,8 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({if (sourceURLs.type != "image") {throw new Error("Image editor invoked for non-image file");}- img.src = sourceURLs.renderableImageURL;- setFileURL(sourceURLs.renderableImageURL);+ img.src = sourceURLs.imageURL;+ setFileURL(sourceURLs.imageURL);setMIMEType(sourceURLs.mimeType);} else {img.src = fileURL;