pl
This commit is contained in:
@@ -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));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user