Skip to content

armgit / ente

Public Imported from GitHub
0

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

pl

Manav Rathie0843485d57c
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 8f9e60d15d..419e34238e 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -1,8 +1,11 @@
import { assertionFailed } from "@/base/assert";
import { decryptBlob } from "@/base/crypto";
+import type { EncryptedBlob } from "@/base/crypto/types";
import log from "@/base/log";
import type { EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
+import { gunzip } from "@/new/photos/utils/gzip";
+import { z } from "zod";
import { fetchFileData } from "./file-data";
/**
@@ -11,6 +14,9 @@ import { fetchFileData } from "./file-data";
*
* @param file An {@link EnteFile} of type video.
*
+ * @returns The HLS playlist as a string, or `undefined` if there is no video
+ * preview associated with the given file.
+ *
* [Note: Video playlist and preview]
*
* In museum's ontology, there is a distinction between two concepts:
@@ -38,12 +44,25 @@ export const hlsPlaylistForFile = async (file: EnteFile) => {
return undefined;
}
- const encryptedPlaylist = await fetchFileData("vid_preview", file.id);
- if (!encryptedPlaylist) return undefined;
+ const playlistFileData = await fetchFileData("vid_preview", file.id);
+ if (!playlistFileData) return undefined;
+
+ const { playlist } = await decryptPlaylistJSON(playlistFileData, file);
- const playlist = new TextDecoder().decode(
- await decryptBlob(encryptedPlaylist, file.key),
- );
log.debug(() => ["hlsPlaylistForFile", playlist]);
return file.id;
};
+
+const PlaylistJSON = z.object({
+ /** The HLS playlist, as a string. */
+ playlist: z.string(),
+});
+
+const decryptPlaylistJSON = async (
+ encryptedPlaylist: EncryptedBlob,
+ file: EnteFile,
+) => {
+ const decryptedBytes = await decryptBlob(encryptedPlaylist, file.key);
+ const jsonString = await gunzip(decryptedBytes);
+ return PlaylistJSON.parse(JSON.parse(jsonString));
+};