π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
scaffold wip 2
Manav Rathib9a8f58dec57
diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.tsindex 555cec7834..749166073b 100644--- a/web/packages/gallery/services/download.ts+++ b/web/packages/gallery/services/download.ts@@ -18,6 +18,7 @@ import { customAPIOrigin } from "ente-base/origins";import {playableVideoBlob,renderableImageBlob,+ type RenderableBlobOpts,} from "ente-gallery/utils/convert";import type { EnteFile } from "ente-media/file";import { FileType } from "ente-media/file-type";@@ -295,16 +296,23 @@ class DownloadManager {*/renderableSourceURLs = async (file: EnteFile,- opts?: { forceConvert?: boolean },+ opts?: RenderableBlobOpts,): Promise<RenderableSourceURLs> => {- const forceConvert = opts?.forceConvert ?? false;- if (forceConvert || !this.renderableSourceURLPromises.has(file.id)) {+ // Keep a separate code path for when the conversion is not needed. The+ // download will already be cached. The (lack of) conversion shouldn't+ // be cached since some other code might also invoke us without setting+ // the avoid conversion option.+ if (opts?.avoidFormatConversion) {++ }++ if (!this.renderableSourceURLPromises.has(file.id)) {this.renderableSourceURLPromises.set(file.id,createRenderableSourceURLs(file,this.fileURLDownloadAndCacheIfNeeded(file),- forceConvert,+ opts,),);}@@ -579,7 +587,7 @@ const wrapErrors = <T>(op: () => Promise<T>) =>const createRenderableSourceURLs = async (file: EnteFile,originalFileURLPromise: Promise<string>,- opts: RenderableSourceURLsOpts,+ opts?: RenderableBlobOpts,): Promise<RenderableSourceURLs> => {const originalFileURL = await originalFileURLPromise;const fileBlob = await fetch(originalFileURL).then((res) => res.blob());@@ -601,7 +609,11 @@ const createRenderableSourceURLs = async (const fileName = file.metadata.title;switch (file.metadata.fileType) {case FileType.image: {- const convertedBlob = await renderableImageBlob(fileBlob, fileName);+ const convertedBlob = await renderableImageBlob(+ fileBlob,+ fileName,+ opts,+ );const convertedURL = existingOrNewObjectURL(convertedBlob);url = convertedURL;originalImageBlob = fileBlob;diff --git a/web/packages/gallery/utils/convert.ts b/web/packages/gallery/utils/convert.tsindex 008e1cb0f0..81645bf1d0 100644--- a/web/packages/gallery/utils/convert.ts+++ b/web/packages/gallery/utils/convert.ts@@ -6,22 +6,6 @@ import { heicToJPEG } from "ente-media/heic-convert";import { convertToMP4 } from "../services/ffmpeg";import { detectFileTypeInfo } from "./detect-type";-export interface RenderableBlobOpts {- /**- * If true, then the conversion step is skipped when for a format that we- * usually always convert, we are able to detect that the browser might be- * able to render the file natively.- *- * [Note: Browser HEIC support]- *- * Currently this has an effect only for HEIC files. Safari can show them- * natively, and if we detect HEIC support (by trying to ask the browser to- * show a small HEIC file), we skip the conversion to JPEG. This is then- * used by the file viewer to bypass the costly Wasm HEIC conversion.- */- avoidFormatConversion?: boolean;-}-/*** Return a new {@link Blob} containing an image's data in a format that the* browser (likely) knows how to render (in an img tag, or on the canvas).@@ -47,7 +31,7 @@ export interface RenderableBlobOpts {* desktop app can natively convert to a JPEG (using ffmpeg), do that and* return the resultant JPEG blob.*- * 4. If this is an HEIC file (and `opts.avoidFormatConversion` was not set),+ * 4. If this is an HEIC file and the browser does not have native HEIC support,* then use our (Wasm) HEIC converter and return the resultant JPEG blob.** 5. Otherwise return the original (with the MIME type if we were able to@@ -58,7 +42,6 @@ export interface RenderableBlobOpts {export const renderableImageBlob = async (imageBlob: Blob,fileName: string,- opts: RenderableBlobOpts,) => {try {const file = new File([imageBlob], fileName);@@ -84,14 +67,17 @@ export const renderableImageBlob = async (// to our web HEIC converter.if (isHEICExtension(extension)) {- // However, if the `avoidFormatConversion` option is set, skip- // conversion if we're able to detect that the browser can- // already render them (e.g. Safari 18+).- if (opts.avoidFormatConversion) {- console.log("TODO implement me");+ // But first, check if the browser already knows how to natively+ // render HEICs, e.g. Safari 18+. In such cases not only is the+ // Wasm conversion unnecessary, the native hardware accelerated+ // support will also be _much_ faster.+ if (mimeType == "image/heic" && /*TODO*/ false) {+ log.debug(+ () => `Using native HEIC support for ${fileName}`,+ );+ } else {+ return await heicToJPEG(imageBlob);}-- return await heicToJPEG(imageBlob);}}