Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add HLS video streaming support for public memory shares

AmanRajSinghMourya65075c093f22
diff --git a/web/apps/memories/src/hls-video.d.ts b/web/apps/memories/src/hls-video.d.ts
new file mode 100644
index 0000000000..6da234c8f1
--- /dev/null
+++ b/web/apps/memories/src/hls-video.d.ts
@@ -0,0 +1,12 @@
+import type { DetailedHTMLProps, VideoHTMLAttributes } from "react";
+
+declare module "react" {
+ namespace JSX {
+ interface IntrinsicElements {
+ "hls-video": DetailedHTMLProps<
+ VideoHTMLAttributes<HTMLVideoElement>,
+ HTMLVideoElement
+ >;
+ }
+ }
+}
diff --git a/web/apps/memories/src/pages/index.tsx b/web/apps/memories/src/pages/index.tsx
index 26bfd84d0d..fd10f9d303 100644
--- a/web/apps/memories/src/pages/index.tsx
+++ b/web/apps/memories/src/pages/index.tsx
@@ -1,19 +1,25 @@
import { keyframes } from "@emotion/react";
import { Box, Link, Typography, styled } from "@mui/material";
-import { LoadingIndicator } from "ente-base/components/loaders";
import { Stack100vhCenter } from "ente-base/components/containers";
import { CustomHead } from "ente-base/components/Head";
+import { LoadingIndicator } from "ente-base/components/loaders";
import { isHTTPErrorWithStatus } from "ente-base/http";
import log from "ente-base/log";
-import { downloadManager } from "ente-gallery/services/download";
+import {
+ downloadManager,
+ type RenderableSourceURLs,
+} from "ente-gallery/services/download";
import { extractCollectionKeyFromShareURL } from "ente-gallery/services/share";
+import type { HLSPlaylistData } from "ente-gallery/services/video";
import type { EnteFile } from "ente-media/file";
import { fileCreationPhotoDate } from "ente-media/file-metadata";
+import { FileType } from "ente-media/file-type";
import {
decryptMemoryShareName,
getPublicMemoryFiles,
getPublicMemoryInfo,
} from "ente-new/albums/services/public-memory";
+import "hls-video-element";
import Head from "next/head";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -39,8 +45,19 @@ export default function PublicMemoryPage() {
useEffect(() => {
const main = async () => {
try {
- // Extract token from pathname (e.g., /ABC123XYZ0)
- const token = window.location.pathname.slice(1);
+ const currentURL = new URL(window.location.href);
+
+ // Extract token from either:
+ // - query param ?t=TOKEN (from server-generated URLs)
+ // - pathname /TOKEN (direct links)
+ let token = currentURL.searchParams.get("t");
+ if (!token) {
+ const path = window.location.pathname.slice(1);
+ // Ignore /memory path prefix
+ if (path && path !== "memory") {
+ token = path;
+ }
+ }
// Root path β†’ redirect to ente.io/memories (or show landing)
if (!token) {
@@ -48,8 +65,6 @@ export default function PublicMemoryPage() {
window.location.href = "https://ente.io/memories";
return;
}
-
- const currentURL = new URL(window.location.href);
const shareKey =
await extractCollectionKeyFromShareURL(currentURL);
@@ -70,18 +85,14 @@ export default function PublicMemoryPage() {
setMemoryName(name);
}
- downloadManager.setPublicMemoryCredentials(token);
+ downloadManager.setPublicMemoryCredentials({
+ accessToken: token,
+ });
const enteFiles = await getPublicMemoryFiles(token, shareKey);
- // Sort files by creation date (newest first)
- const sortedFiles = [...enteFiles].sort((a, b) => {
- const dateA = fileCreationPhotoDate(a).getTime();
- const dateB = fileCreationPhotoDate(b).getTime();
- return dateB - dateA;
- });
-
- setFiles(sortedFiles);
+ // Preserve the order from the server (matches mobile app's intended order)
+ setFiles(enteFiles);
} catch (e) {
if (
isHTTPErrorWithStatus(e, 401) ||
@@ -205,7 +216,7 @@ interface MemoryViewerProps {
onPrev: () => void;
}
-const AUTO_PROGRESS_DURATION_MS = 5000;
+const IMAGE_AUTO_PROGRESS_DURATION_MS = 5000;
const progressFillAnimation = keyframes`
from { width: 0%; }
@@ -222,16 +233,33 @@ const MemoryViewer: React.FC<MemoryViewerProps> = ({
const currentFile = files[currentIndex]!;
const [paused, setPaused] = useState(false);
const [fileLoaded, setFileLoaded] = useState(false);
+ // For videos, track if duration is known (prevents premature animation start).
+ const [videoDurationKnown, setVideoDurationKnown] = useState(false);
+ // For videos, we track the duration in ms; for images, use the constant.
+ const [progressDuration, setProgressDuration] = useState(
+ IMAGE_AUTO_PROGRESS_DURATION_MS,
+ );
- // Reset loaded state when file changes.
+ const isVideo = currentFile.metadata.fileType === FileType.video;
+
+ // Reset loaded state and duration when file changes.
useEffect(() => {
setFileLoaded(false);
+ setVideoDurationKnown(false);
+ // Reset to image duration; video will update this when it loads.
+ setProgressDuration(IMAGE_AUTO_PROGRESS_DURATION_MS);
}, [currentIndex]);
const handleFullLoad = useCallback(() => {
setFileLoaded(true);
}, []);
+ const handleVideoDuration = useCallback((durationSeconds: number) => {
+ // Convert seconds to milliseconds for the progress bar.
+ setProgressDuration(durationSeconds * 1000);
+ setVideoDurationKnown(true);
+ }, []);
+
// Preload next file's thumbnail for smoother navigation.
useEffect(() => {
if (currentIndex < files.length - 1) {
@@ -262,8 +290,14 @@ const MemoryViewer: React.FC<MemoryViewerProps> = ({
<ProgressIndicator
total={files.length}
current={currentIndex}
- paused={paused || !fileLoaded}
+ paused={
+ paused ||
+ !fileLoaded ||
+ (isVideo && !videoDurationKnown)
+ }
+ duration={progressDuration}
onComplete={onNext}
+ isVideo={isVideo}
/>
</HeaderSection>
<PhotoContainer
@@ -271,11 +305,22 @@ const MemoryViewer: React.FC<MemoryViewerProps> = ({
onMouseLeave={() => setPaused(false)}
onClick={handleClick}
>
- <PhotoImage
- file={currentFile}
- onFullLoad={handleFullLoad}
- dateBadge={<DateBadge file={currentFile} />}
- />
+ {isVideo ? (
+ <VideoPlayer
+ file={currentFile}
+ onReady={handleFullLoad}
+ onDuration={handleVideoDuration}
+ onEnded={onNext}
+ paused={paused}
+ dateBadge={<DateBadge file={currentFile} />}
+ />
+ ) : (
+ <PhotoImage
+ file={currentFile}
+ onFullLoad={handleFullLoad}
+ dateBadge={<DateBadge file={currentFile} />}
+ />
+ )}
</PhotoContainer>
<Footer />
</ContentContainer>
@@ -337,14 +382,19 @@ interface ProgressIndicatorProps {
total: number;
current: number;
paused: boolean;
+ duration: number;
onComplete: () => void;
+ /** If true, the progress bar won't auto-advance (video handles its own end). */
+ isVideo?: boolean;
}
const ProgressIndicator: React.FC<ProgressIndicatorProps> = ({
total,
current,
paused,
+ duration,
onComplete,
+ isVideo,
}) => {
// Calculate the total width: 30px per bar + 12px gap between bars
const totalWidth = total * 30 + (total - 1) * 12;
@@ -364,7 +414,7 @@ const ProgressIndicator: React.FC<ProgressIndicatorProps> = ({
<ProgressBar
// Use a unique key for the active bar so it remounts
// (restarting the CSS animation) when navigating.
- key={i === current ? `active-${current}` : i}
+ key={i === current ? `active-${current}-${duration}` : i}
state={
i < current
? "past"
@@ -373,7 +423,11 @@ const ProgressIndicator: React.FC<ProgressIndicatorProps> = ({
: "future"
}
paused={paused}
- onComplete={i === current ? onComplete : undefined}
+ duration={duration}
+ // For videos, don't trigger onComplete from animation - video's onEnded handles it.
+ onComplete={
+ i === current && !isVideo ? onComplete : undefined
+ }
/>
))}
</Box>
@@ -383,12 +437,14 @@ const ProgressIndicator: React.FC<ProgressIndicatorProps> = ({
interface ProgressBarProps {
state: "past" | "active" | "future";
paused: boolean;
+ duration: number;
onComplete?: () => void;
}
const ProgressBar: React.FC<ProgressBarProps> = ({
state,
paused,
+ duration,
onComplete,
}) => {
return (
@@ -419,12 +475,10 @@ const ProgressBar: React.FC<ProgressBarProps> = ({
? "100%"
: "0%",
...(state === "active" && {
- animation: `${progressFillAnimation} ${AUTO_PROGRESS_DURATION_MS}ms linear forwards`,
+ animation: `${progressFillAnimation} ${duration}ms linear forwards`,
animationPlayState: paused ? "paused" : "running",
}),
- ...(state === "past" && {
- transition: "none",
- }),
+ ...(state === "past" && { transition: "none" }),
}}
/>
</Box>
@@ -534,6 +588,232 @@ const PhotoImage: React.FC<PhotoImageProps> = ({
);
};
+interface VideoPlayerProps {
+ file: EnteFile;
+ onReady?: () => void;
+ onDuration?: (durationSeconds: number) => void;
+ onEnded?: () => void;
+ paused?: boolean;
+ dateBadge?: React.ReactNode;
+}
+
+const VideoPlayer: React.FC<VideoPlayerProps> = ({
+ file,
+ onReady,
+ onDuration,
+ onEnded,
+ paused,
+ dateBadge,
+}) => {
+ const [hlsData, setHlsData] = useState<HLSPlaylistData | undefined>(
+ undefined,
+ );
+ const [videoURL, setVideoURL] = useState<string | undefined>(undefined);
+ const [thumbnailURL, setThumbnailURL] = useState<string | undefined>(
+ undefined,
+ );
+ const [isLoading, setIsLoading] = useState(true);
+ const [error, setError] = useState(false);
+ const videoRef = useRef<HTMLVideoElement>(null);
+ const onReadyRef = useRef(onReady);
+ const onDurationRef = useRef(onDuration);
+ const onEndedRef = useRef(onEnded);
+
+ onReadyRef.current = onReady;
+ onDurationRef.current = onDuration;
+ onEndedRef.current = onEnded;
+
+ // Load video URL (try HLS first, fallback to direct download)
+ useEffect(() => {
+ let cancelled = false;
+ setIsLoading(true);
+ setError(false);
+ setVideoURL(undefined);
+ setHlsData(undefined);
+
+ const load = async () => {
+ try {
+ // First load thumbnail as poster
+ const thumbURL =
+ await downloadManager.renderableThumbnailURL(file);
+ if (!cancelled && thumbURL) {
+ setThumbnailURL(thumbURL);
+ }
+
+ // Try HLS streaming first (better quality, adaptive bitrate)
+ const hlsPlaylistData =
+ await downloadManager.hlsPlaylistDataForPublicMemory(file);
+ if (
+ !cancelled &&
+ typeof hlsPlaylistData === "object" &&
+ hlsPlaylistData?.playlistURL
+ ) {
+ setHlsData(hlsPlaylistData);
+ return;
+ }
+
+ // Fallback to direct video download
+ const sourceURLs: RenderableSourceURLs =
+ await downloadManager.renderableSourceURLs(file);
+ if (!cancelled && sourceURLs.type === "video") {
+ setVideoURL(sourceURLs.videoURL);
+ }
+ } catch (e) {
+ log.error("Failed to load video", e);
+ if (!cancelled) {
+ setError(true);
+ setIsLoading(false);
+ }
+ }
+ };
+ load();
+ return () => {
+ cancelled = true;
+ };
+ }, [file]);
+
+ // Handle pause/play state
+ useEffect(() => {
+ const video = videoRef.current;
+ if (!video || (!videoURL && !hlsData)) return;
+
+ if (paused) {
+ video.pause();
+ } else {
+ video.play().catch(() => {
+ // Autoplay may be blocked; ignore
+ });
+ }
+ }, [paused, videoURL, hlsData]);
+
+ const handleLoadedMetadata = useCallback(() => {
+ const video = videoRef.current;
+ if (video && !isNaN(video.duration) && video.duration > 0) {
+ onDurationRef.current?.(video.duration);
+ }
+ }, []);
+
+ const handleCanPlay = useCallback(() => {
+ setIsLoading(false);
+ onReadyRef.current?.();
+ // Auto-play when ready
+ const video = videoRef.current;
+ if (video) {
+ video.play().catch(() => {
+ // Autoplay may be blocked
+ });
+ }
+ }, []);
+
+ const handleEnded = useCallback(() => {
+ onEndedRef.current?.();
+ }, []);
+
+ if (error) {
+ return (
+ <Box
+ sx={{
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width: "100%",
+ height: "100%",
+ }}
+ >
+ <Typography sx={{ color: "rgba(255,255,255,0.7)" }}>
+ Unable to play video
+ </Typography>
+ </Box>
+ );
+ }
+
+ return (
+ <Box
+ sx={{
+ position: "relative",
+ display: "inline-block",
+ maxWidth: "100%",
+ maxHeight: "100%",
+ borderRadius: "24px",
+ overflow: "hidden",
+ }}
+ >
+ {/* Loading overlay */}
+ {isLoading && (
+ <Box
+ sx={{
+ position: "absolute",
+ inset: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
+ zIndex: 2,
+ }}
+ >
+ <LoadingIndicator />
+ </Box>
+ )}
+ {/* HLS video element (when HLS streaming is available) */}
+ {hlsData && (
+ <hls-video
+ ref={videoRef as React.RefObject<HTMLVideoElement>}
+ src={hlsData.playlistURL}
+ poster={thumbnailURL}
+ playsInline
+ onLoadedMetadata={handleLoadedMetadata}
+ onCanPlay={handleCanPlay}
+ onEnded={handleEnded}
+ style={{
+ display: "block",
+ maxWidth: "100%",
+ maxHeight: "100%",
+ objectFit: "contain",
+ userSelect: "none",
+ }}
+ />
+ )}
+ {/* Regular video element (fallback when HLS is not available) */}
+ {!hlsData && videoURL && (
+ <video
+ ref={videoRef}
+ src={videoURL}
+ poster={thumbnailURL}
+ playsInline
+ muted={false}
+ onLoadedMetadata={handleLoadedMetadata}
+ onCanPlay={handleCanPlay}
+ onEnded={handleEnded}
+ style={{
+ display: "block",
+ maxWidth: "100%",
+ maxHeight: "100%",
+ objectFit: "contain",
+ userSelect: "none",
+ }}
+ />
+ )}
+ {/* Show thumbnail while video loads */}
+ {!videoURL && !hlsData && thumbnailURL && (
+ <img
+ src={thumbnailURL}
+ alt=""
+ style={{
+ display: "block",
+ maxWidth: "100%",
+ maxHeight: "100%",
+ objectFit: "contain",
+ userSelect: "none",
+ pointerEvents: "none",
+ }}
+ />
+ )}
+ {/* Date badge positioned over the video */}
+ {dateBadge}
+ </Box>
+ );
+};
+
interface FileImageProps {
file: EnteFile;
}
@@ -638,13 +918,7 @@ const getOrdinalSuffix = (n: number): string => {
};
const Footer: React.FC = () => (
- <Box
- sx={{
- flexShrink: 0,
- textAlign: "center",
- width: "100%",
- }}
- >
+ <Box sx={{ flexShrink: 0, textAlign: "center", width: "100%" }}>
<Link
href="https://ente.io"
target="_blank"
diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.ts
index 08ab5fdd1e..e772b02d79 100644
--- a/web/packages/gallery/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@ -19,7 +19,12 @@ import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { decodeLivePhoto } from "ente-media/live-photo";
+import {
+ authenticatedPublicMemoryRequestHeaders,
+ type PublicMemoryCredentials,
+} from "ente-new/albums/services/public-memory";
import { playableVideoURL, renderableImageBlob } from "./convert";
+import { hlsPlaylistDataForFile, type HLSPlaylistDataForFile } from "./video";
/**
* URL(s) for the original image or video, alongwith with potential conversions
@@ -108,6 +113,11 @@ class DownloadManager {
* context of the public albums app.
*/
publicAlbumsCredentials: PublicAlbumsCredentials | undefined;
+ /**
+ * Credentials that should be used to download files when we're in the
+ * context of the public memory share app.
+ */
+ publicMemoryCredentials: PublicMemoryCredentials | undefined;
/**
* Access token for downloading files when we're in the context of a
* public memory share.
@@ -192,6 +202,7 @@ class DownloadManager {
*/
logout() {
this.publicAlbumsCredentials = undefined;
+ this.publicMemoryCredentials = undefined;
this.publicMemoryAccessToken = undefined;
this.thumbnailURLPromises.clear();
this.fileURLPromises.clear();
@@ -211,11 +222,14 @@ class DownloadManager {
}
/**
- * Set the access token for downloading files when we're running in the
- * context of a public memory share.
+ * Set the credentials that should be used for download files when we're
+ * running in the context of a public memory share.
*/
- setPublicMemoryCredentials(accessToken: string | undefined) {
- this.publicMemoryAccessToken = accessToken;
+ setPublicMemoryCredentials(
+ credentials: PublicMemoryCredentials | undefined,
+ ) {
+ this.publicMemoryCredentials = credentials;
+ this.publicMemoryAccessToken = credentials?.accessToken;
}
/**
@@ -324,10 +338,10 @@ class DownloadManager {
};
private async _downloadThumbnail(file: EnteFile) {
- if (this.publicMemoryAccessToken) {
+ if (this.publicMemoryCredentials) {
return publicMemory_downloadThumbnail(
file,
- this.publicMemoryAccessToken,
+ this.publicMemoryCredentials,
);
} else if (this.publicAlbumsCredentials) {
return publicAlbums_downloadThumbnail(
@@ -339,6 +353,23 @@ class DownloadManager {
}
}
+ /**
+ * Return HLS playlist data for a file when viewing a public memory share.
+ *
+ * @returns HLS playlist data if available, or undefined if HLS streaming
+ * is not available for this file.
+ */
+ hlsPlaylistDataForPublicMemory = async (
+ file: EnteFile,
+ ): Promise<HLSPlaylistDataForFile> => {
+ if (!this.publicMemoryCredentials) return undefined;
+ return hlsPlaylistDataForFile(
+ file,
+ undefined,
+ this.publicMemoryCredentials,
+ );
+ };
+
/**
* Return a URL (and associated metadata) that can be used to show the given
* {@link file} within the app, converting its format (on the fly) if needed
@@ -550,6 +581,11 @@ class DownloadManager {
file,
this.publicAlbumsCredentials,
);
+ } else if (this.publicMemoryCredentials) {
+ return publicMemory_downloadFile(
+ file,
+ this.publicMemoryCredentials,
+ );
} else {
return photos_downloadFile(file, opts);
}
@@ -870,17 +906,19 @@ const publicAlbums_downloadFile = async (
};
/**
- * The publicMemory_* helpers are used for thumbnail fetches when we're
- * running in the context of a public memory share page.
+ * The various publicMemory_* functions are used for the actual downloads when
+ * we're running in the context of a public memory share.
*/
const publicMemory_downloadThumbnail = async (
file: EnteFile,
- accessToken: string,
+ credentials: PublicMemoryCredentials,
) => {
const customOrigin = await customAPIOrigin();
const getThumbnail = async () => {
if (customOrigin) {
+ // See: [Note: Passing credentials for self-hosted file fetches]
+ const { accessToken } = credentials;
const params = new URLSearchParams({ accessToken });
return fetch(
`${customOrigin}/public-memory/files/preview/${file.id}?${params.toString()}`,
@@ -890,9 +928,8 @@ const publicMemory_downloadThumbnail = async (
return fetch(
await apiURL(`/public-memory/files/preview/${file.id}`),
{
- headers: authenticatedPublicAlbumsRequestHeaders({
- accessToken,
- }),
+ headers:
+ authenticatedPublicMemoryRequestHeaders(credentials),
},
);
}
@@ -901,3 +938,27 @@ const publicMemory_downloadThumbnail = async (
const res = await retryEnsuringHTTPOk(getThumbnail);
return new Uint8Array(await res.arrayBuffer());
};
+
+const publicMemory_downloadFile = async (
+ file: EnteFile,
+ credentials: PublicMemoryCredentials,
+) => {
+ const customOrigin = await customAPIOrigin();
+
+ const getFile = async () => {
+ if (customOrigin) {
+ // See: [Note: Passing credentials for self-hosted file fetches]
+ const { accessToken } = credentials;
+ const params = new URLSearchParams({ accessToken });
+ return fetch(
+ `${customOrigin}/public-memory/files/${file.id}?${params.toString()}`,
+ );
+ } else {
+ return fetch(await apiURL(`/public-memory/files/${file.id}`), {
+ headers: authenticatedPublicMemoryRequestHeaders(credentials),
+ });
+ }
+ };
+
+ return retryEnsuringHTTPOk(getFile);
+};
diff --git a/web/packages/gallery/services/file-data.ts b/web/packages/gallery/services/file-data.ts
index 3d7165c277..943cded6ae 100644
--- a/web/packages/gallery/services/file-data.ts
+++ b/web/packages/gallery/services/file-data.ts
@@ -9,6 +9,10 @@ import {
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
import type { EnteFile } from "ente-media/file";
+import {
+ authenticatedPublicMemoryRequestHeaders,
+ type PublicMemoryCredentials,
+} from "ente-new/albums/services/public-memory";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod";
@@ -125,6 +129,7 @@ export const fetchFileData = async (
type: FileDataType,
fileID: number,
publicAlbumsCredentials?: PublicAlbumsCredentials,
+ publicMemoryCredentials?: PublicMemoryCredentials,
): Promise<RemoteFileData | undefined> => {
const params = new URLSearchParams({
type,
@@ -135,7 +140,13 @@ export const fetchFileData = async (
});
let res: Response;
- if (publicAlbumsCredentials) {
+ if (publicMemoryCredentials) {
+ const url = await apiURL("/public-memory/file-data");
+ const headers = authenticatedPublicMemoryRequestHeaders(
+ publicMemoryCredentials,
+ );
+ res = await fetch(`${url}?${params.toString()}`, { headers });
+ } else if (publicAlbumsCredentials) {
const url = await apiURL("/public-collection/files/data/fetch");
const headers = authenticatedPublicAlbumsRequestHeaders(
publicAlbumsCredentials,
@@ -357,11 +368,18 @@ export const fetchFilePreviewData = async (
type: FileDataType,
fileID: number,
publicAlbumsCredentials?: PublicAlbumsCredentials,
+ publicMemoryCredentials?: PublicMemoryCredentials,
): Promise<string | undefined> => {
const params = new URLSearchParams({ type, fileID: fileID.toString() });
let res: Response;
- if (publicAlbumsCredentials) {
+ if (publicMemoryCredentials) {
+ const headers = authenticatedPublicMemoryRequestHeaders(
+ publicMemoryCredentials,
+ );
+ const url = await apiURL("/public-memory/files/data/preview");
+ res = await fetch(`${url}?${params.toString()}`, { headers });
+ } else if (publicAlbumsCredentials) {
const headers = authenticatedPublicAlbumsRequestHeaders(
publicAlbumsCredentials,
);
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 9962f46516..ad55e38616 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -12,6 +12,7 @@ import { ensureAuthToken } from "ente-base/token";
import { uniqueFilesByID } from "ente-gallery/utils/file";
import { fileLogID, type EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
+import type { PublicMemoryCredentials } from "ente-new/albums/services/public-memory";
import { updateFilePublicMagicMetadata } from "ente-new/photos/services/file";
import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";
import { savedTrashItemFileIDs } from "ente-new/photos/services/trash";
@@ -330,6 +331,7 @@ export type HLSPlaylistDataForFile = HLSPlaylistData | "skip" | undefined;
export const hlsPlaylistDataForFile = async (
file: EnteFile,
publicAlbumsCredentials?: PublicAlbumsCredentials,
+ publicMemoryCredentials?: PublicMemoryCredentials,
): Promise<HLSPlaylistDataForFile> => {
ensurePrecondition(file.metadata.fileType == FileType.video);
@@ -341,6 +343,7 @@ export const hlsPlaylistDataForFile = async (
"vid_preview",
file.id,
publicAlbumsCredentials,
+ publicMemoryCredentials,
);
if (!playlistFileData) return undefined;
@@ -358,6 +361,7 @@ export const hlsPlaylistDataForFile = async (
"vid_preview",
file.id,
publicAlbumsCredentials,
+ publicMemoryCredentials,
);
if (!videoURL) return undefined;
diff --git a/web/packages/new/albums/services/public-memory.ts b/web/packages/new/albums/services/public-memory.ts
index 2bf41ff39c..c425635337 100644
--- a/web/packages/new/albums/services/public-memory.ts
+++ b/web/packages/new/albums/services/public-memory.ts
@@ -2,11 +2,33 @@ import { decryptBoxBytes } from "ente-base/crypto";
import {
authenticatedPublicAlbumsRequestHeaders,
ensureOk,
+ type PublicAlbumsCredentials,
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
-import { decryptRemoteFile, RemoteEnteFile, type EnteFile } from "ente-media/file";
+import {
+ decryptRemoteFile,
+ RemoteEnteFile,
+ type EnteFile,
+} from "ente-media/file";
import { z } from "zod";
+/**
+ * Credentials for accessing a public memory share.
+ */
+export interface PublicMemoryCredentials {
+ accessToken: string;
+}
+
+/**
+ * Request headers for authenticated public memory share requests.
+ */
+export const authenticatedPublicMemoryRequestHeaders = (
+ credentials: PublicMemoryCredentials,
+): ReturnType<typeof authenticatedPublicAlbumsRequestHeaders> =>
+ authenticatedPublicAlbumsRequestHeaders(
+ credentials as PublicAlbumsCredentials,
+ );
+
/**
* Information about a public memory share fetched from remote.
*/
@@ -83,11 +105,7 @@ export const getPublicMemoryFiles = async (
// The file's key is re-encrypted to the per-share key.
// Override the file's encryptedKey/nonce with the share-level values
// so that decryptRemoteFile can decrypt using the shareKey.
- const remoteFile = {
- ...file,
- encryptedKey,
- keyDecryptionNonce,
- };
+ const remoteFile = { ...file, encryptedKey, keyDecryptionNonce };
const decrypted = await decryptRemoteFile(remoteFile, shareKey);
enteFiles.push(decrypted);
}