Skip to content

armgit / ente

Public Imported from GitHub
0

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

elsewhere

Manav Rathiafea991e16d6
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 2c16dd77be..9b516058cf 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -8,7 +8,6 @@ import { LoadingButton } from "@/base/components/mui/LoadingButton";
import { useIsSmallWidth } from "@/base/components/utils/hooks";
import { type ModalVisibilityProps } from "@/base/components/utils/modal";
import { useBaseContext } from "@/base/context";
-import { isDevBuild } from "@/base/env";
import { lowercaseExtension } from "@/base/file-name";
import { formattedListJoin, ut } from "@/base/i18n";
import type { LocalUser } from "@/base/local-user";
@@ -54,7 +53,6 @@ import React, {
useRef,
useState,
} from "react";
-import { hlsPlaylistForFile } from "../../services/video";
import {
fileInfoExifForFile,
updateItemDataAlt,
@@ -520,15 +518,6 @@ export const FileViewer: React.FC<FileViewerProps> = ({
}
})();
- if (
- isDevBuild &&
- process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING
- ) {
- if (file.metadata.fileType == FileType.video) {
- void hlsPlaylistForFile(file);
- }
- }
-
const annotation: FileViewerFileAnnotation = {
fileID,
isOwnFile,
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index 1684a59714..6f6412d5ee 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -1,3 +1,4 @@
+import { isDevBuild } from "@/base/env";
import log from "@/base/log";
import type { FileInfoExif } from "@/gallery/components/FileInfo";
import {
@@ -5,6 +6,7 @@ import {
type LivePhotoSourceURL,
} from "@/gallery/services/download";
import { extractRawExif, parseExif } from "@/gallery/services/exif";
+import { hlsPlaylistForFile } from "@/gallery/services/video";
import type { EnteFile } from "@/media/file";
import { fileCaption } from "@/media/file-metadata";
import { FileType } from "@/media/file-type";
@@ -96,6 +98,17 @@ export type ItemData = PhotoSwipeSlideData & {
* portion of the live photo.
*/
videoURL?: string;
+ /**
+ * The object URL to an HLS playlist that can be used to play the video
+ * associated with the file in a streaming manner.
+ *
+ * This will only be defined for videos for which a corresponding streamable
+ * version has been created.
+ *
+ * Only one of {@link videoURL} or {@link videoPlaylistURL} will be set at a
+ * time.
+ */
+ videoPlaylistURL?: string;
/**
* `true` if we should indicate to the user that we're still fetching data
* for this file.
@@ -394,6 +407,19 @@ const enqueueUpdates = async (file: EnteFile) => {
}
case FileType.video: {
+ if (
+ isDevBuild &&
+ process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING
+ ) {
+ if (file.metadata.fileType == FileType.video) {
+ const playlistURL = await hlsPlaylistForFile(file);
+ if (playlistURL) {
+ update({ videoPlaylistURL: playlistURL });
+ break;
+ }
+ }
+ }
+
const sourceURLs =
await downloadManager.renderableSourceURLs(file);
update({ videoURL: sourceURLs.url as string });
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index ba8bebe24b..b11ae787b2 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -305,12 +305,10 @@ export class FileViewerPhotoSwipe {
pswp.refreshSlideContent(index),
);
- const { videoURL, ...rest } = itemData;
- if (itemData.fileType === FileType.video && videoURL) {
- itemData = {
- ...rest,
- html: videoHTML(videoURL, !!disableDownload),
- };
+ const { videoURL, videoPlaylistURL, ...rest } = itemData;
+ const url = videoPlaylistURL ?? videoURL;
+ if (itemData.fileType === FileType.video && url) {
+ itemData = { ...rest, html: videoHTML(url, !!disableDownload) };
}
return itemData;
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index a0be8b45ed..565eda33b8 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -91,7 +91,11 @@ export const hlsPlaylistForFile = async (file: EnteFile) => {
const playlist = playlistTemplate.replaceAll("output.ts", videoURL);
log.debug(() => ["hlsPlaylistForFile", playlist]);
- return file.id;
+
+ const playlistBlob = new Blob([playlist])
+ const playlistURL = URL.createObjectURL(playlistBlob);
+
+ return playlistURL;
};
const PlaylistJSON = z.object({