diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts index 21c703633a..9c5234fea7 100644 --- a/web/apps/photos/src/services/upload/uploadManager.ts +++ b/web/apps/photos/src/services/upload/uploadManager.ts @@ -14,6 +14,7 @@ import { type UploadPhase, type UploadResult, } from "ente-gallery/services/upload"; +import { processVideoNewUpload } from "ente-gallery/services/video"; import type { Collection } from "ente-media/collection"; import { decryptFile, @@ -647,6 +648,7 @@ class UploadManager { uploadResult == "uploadedWithStaticThumbnail") ) { indexNewUpload(decryptedFile, uploadItem); + processVideoNewUpload(decryptedFile, uploadItem); } this.updateExistingFiles(decryptedFile); } @@ -657,7 +659,7 @@ class UploadManager { ); return uploadResult; } catch (e) { - log.error("failed to do post file upload action", e); + log.error("Post file upload action failed", e); return "failed"; } } diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts index 28be72b523..aa1777126d 100644 --- a/web/packages/gallery/services/video.ts +++ b/web/packages/gallery/services/video.ts @@ -1,11 +1,14 @@ import { decryptBlob } from "ente-base/crypto"; import type { EncryptedBlob } from "ente-base/crypto/types"; +import log from "ente-base/log"; import type { EnteFile } from "ente-media/file"; import { FileType } from "ente-media/file-type"; +import { settingsSnapshot } from "ente-new/photos/services/settings"; import { gunzip } from "ente-new/photos/utils/gzip"; import { ensurePrecondition } from "ente-utils/ensure"; import { z } from "zod"; import { fetchFileData, fetchFilePreviewData } from "./file-data"; +import type { UploadItem } from "./upload"; export interface HLSPlaylistData { /** A data URL to a HLS playlist that streams the video. */ @@ -181,3 +184,30 @@ const blobToDataURL = (blob: Blob) => reader.onload = () => resolve(reader.result as string); reader.readAsDataURL(blob); }); + +/** + * Create a streamable HLS playlist for a video uploaded from this client. + * + * This function is called by the uploader when it uploads a new file from this + * client, allowing us to create its streamable variant without needing to + * redownload the video. + * + * @param file The {@link EnteFile} that got uploaded (video or otherwise). + * + * @param uploadItem The item that was uploaded. This can be used to get at the + * contents of the file that got uploaded. + */ +export const processVideoNewUpload = ( + file: EnteFile, + uploadItem: UploadItem, +) => { + // TODO(HLS): + if (!isVideoProcessingEnabled()) return; + if (file.metadata.fileType !== FileType.video) return; + log.debug(() => ["gen-hls", { file, uploadItem }]); + // void worker().then((w) => w.onUpload(file, uploadItem)); +}; + +export const isVideoProcessingEnabled = () => + process.env.NEXT_PUBLIC_ENTE_WIP_VIDEO_STREAMING && + settingsSnapshot().isInternalUser;