Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

step 2 wip

Manav Rathid8e3807049a2
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index b8e1bb2b7c..05c6c7bdff 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -1,10 +1,7 @@
import { isDevBuild } from "ente-base/env";
import log from "ente-base/log";
import type { FileInfoExif } from "ente-gallery/components/FileInfo";
-import {
- downloadManager,
- type LivePhotoSourceURL,
-} from "ente-gallery/services/download";
+import { downloadManager } from "ente-gallery/services/download";
import { extractRawExif, parseExif } from "ente-gallery/services/exif";
import { hlsPlaylistDataForFile } from "ente-gallery/services/video";
import type { EnteFile } from "ente-media/file";
@@ -407,67 +404,55 @@ const enqueueUpdates = async (file: EnteFile) => {
}
try {
- switch (fileType) {
- case FileType.image: {
- const sourceURLs =
- await downloadManager.renderableSourceURLs(file);
- const imageURL = ensureString(sourceURLs.url);
- const originalImageBlob = sourceURLs.originalImageBlob!;
+ if (isDevBuild && process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING) {
+ if (file.metadata.fileType == FileType.video) {
+ const playlistData = await hlsPlaylistDataForFile(file);
+ if (playlistData) {
+ const {
+ playlistURL: videoPlaylistURL,
+ width,
+ height,
+ } = playlistData;
+ update({ videoPlaylistURL, width, height });
+ return;
+ }
+ }
+ }
+
+ const sourceURLs = await downloadManager.renderableSourceURLs(file);
+
+ switch (sourceURLs.type) {
+ case "image": {
+ const imageURL = sourceURLs.renderableImageURL;
+ const originalImageBlob = sourceURLs.originalImageBlob;
const itemData = await withDimensionsIfPossible(imageURL);
update({ ...itemData, imageURL, originalImageBlob });
break;
}
- case FileType.video: {
- if (
- isDevBuild &&
- process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING
- ) {
- if (file.metadata.fileType == FileType.video) {
- const playlistData = await hlsPlaylistDataForFile(file);
- if (playlistData) {
- const {
- playlistURL: videoPlaylistURL,
- width,
- height,
- } = playlistData;
- update({ videoPlaylistURL, width, height });
- break;
- }
- }
- }
-
- const sourceURLs =
- await downloadManager.renderableSourceURLs(file);
- update({ videoURL: sourceURLs.url as string });
+ case "video": {
+ update({ videoURL: sourceURLs.playableVideoURL });
break;
}
- case FileType.livePhoto: {
- const sourceURLs =
- await downloadManager.renderableSourceURLs(file);
- const livePhotoSourceURLs =
- sourceURLs.url as LivePhotoSourceURL;
+ case "livePhoto": {
// The image component of a live photo usually is an HEIC file,
- // which cannot be displayed natively by browsers and needs a
- // conversion, which is slow on web (faster on desktop). We
+ // which cannot be displayed natively by many browsers and needs
+ // a conversion, which is slow on web (faster on desktop). We
// already have both components available since they're part of
// the same zip. And in the UI, the first (default) interaction
// is to loop the live video.
//
// For these reasons, we resolve with the video first, then
// resolve with the image.
- const videoURL = await livePhotoSourceURLs.video();
+ const videoURL = await sourceURLs.video();
update({
videoURL,
isContentLoading: true,
isContentZoomable: false,
});
- const imageURL = ensureString(
- await livePhotoSourceURLs.image(),
- );
- const originalImageBlob =
- livePhotoSourceURLs.originalImageBlob()!;
+ const imageURL = await sourceURLs.image();
+ const originalImageBlob = sourceURLs.originalImageBlob()!;
update({
...(await withDimensionsIfPossible(imageURL)),
imageURL,
diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.ts
index b344dcc5d3..6c31a1e11f 100644
--- a/web/packages/gallery/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@ -83,19 +83,19 @@ export type RenderableSourceURLs =
* as a promise since we might want to operate on the different
* components of a live image in a staggered order.
*/
- image: () => Promise<string | undefined>;
+ renderableImageURL: () => 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.
*/
- originalImageBlob: () => Blob | undefined;
+ originalImageBlob: () => Blob;
/**
* Similar to the {@link playableVideoURL} 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.
*/
- video: () => Promise<string | undefined>;
+ playableVideoURL: () => Promise<string>;
};
/**
@@ -607,25 +607,21 @@ const createRenderableSourceURLs = async (
const fileBlob = await fetch(originalFileURL).then((res) => res.blob());
const existingOrNewObjectURL = (convertedBlob: Blob | null | undefined) =>
- convertedBlob
- ? convertedBlob === fileBlob
- ? originalFileURL
- : URL.createObjectURL(convertedBlob)
- : 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 convertedURL = existingOrNewObjectURL(convertedBlob);
- // TODO
- const url = convertedURL!;
+ const renderableImageURL = existingOrNewObjectURL(convertedBlob);
const originalImageBlob = fileBlob;
const mimeType = convertedBlob.type;
return {
type: "image",
- renderableImageURL: url,
+ renderableImageURL,
originalImageBlob,
mimeType,
};
@@ -652,27 +648,17 @@ const createRenderableSourceURLs = async (
};
const getOriginalImageBlob = () => {
- try {
- return new Blob([livePhoto.imageData]);
- } catch {
- //ignore and return null
- return undefined;
- }
+ return new Blob([livePhoto.imageData]);
};
const getRenderableLivePhotoVideoURL = async () => {
- try {
- const videoBlob = new Blob([livePhoto.videoData]);
- const convertedVideoBlob = await playableVideoBlob(
- livePhoto.videoFileName,
- videoBlob,
- );
- if (!convertedVideoBlob) return undefined;
- return URL.createObjectURL(convertedVideoBlob);
- } catch {
- //ignore and return null
- return undefined;
- }
+ const videoBlob = new Blob([livePhoto.videoData]);
+ const convertedVideoBlob = await playableVideoBlob(
+ livePhoto.videoFileName,
+ videoBlob,
+ );
+ if (!convertedVideoBlob) return undefined;
+ return URL.createObjectURL(convertedVideoBlob);
};
return {
diff --git a/web/packages/gallery/utils/convert.ts b/web/packages/gallery/utils/convert.ts
index 98821894ec..956234c7a7 100644
--- a/web/packages/gallery/utils/convert.ts
+++ b/web/packages/gallery/utils/convert.ts
@@ -168,6 +168,8 @@ const testHEICDataURL =
* - 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.
*/
export const playableVideoBlob = async (fileName: string, videoBlob: Blob) => {
const converted = async () => {
@@ -177,7 +179,7 @@ export const playableVideoBlob = async (fileName: string, videoBlob: Blob) => {
return new Blob([convertedBlob], { type: "video/mp4" });
} catch (e) {
log.error(`Video conversion failed for ${fileName}`, e);
- return null;
+ return videoBlob;
}
};