Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

videoPreviewSource.ts

54 lines1.8 KB

1import type { AssetResource, ChatFileAttachment, EnvironmentId } from "@t3tools/contracts";
2​
3import type { DraftComposerFileAttachment } from "./composerImages";
4import type { MediaActionsSource } from "./mediaActions";
5​
6export type MediaVideoPreviewSource = {
7 readonly type: "media";
8 readonly name: string;
9 readonly mimeType: string;
10 readonly sourceIdentifier?: string;
11 readonly srcFragment?: string;
12 readonly actionsSource?: MediaActionsSource;
13} & (
14 | { readonly uri: string }
15 | {
16 readonly environmentId: EnvironmentId;
17 readonly resource: Extract<AssetResource, { readonly _tag: "media-file" }>;
18 }
19);
20​
21/** Resolves the current capability without making it the identity of the video. */
22export function mediaVideoPreviewUri(
23 source: MediaVideoPreviewSource,
24 assetUrl: string | null,
25): string | null {
26 if ("uri" in source) return source.uri;
27 return assetUrl === null ? null : assetUrl + (source.srcFragment ?? "");
29​
30/** Keeps thumbnails independent of refreshed asset signatures and scoped to their environment. */
31export function mediaVideoThumbnailKey(source: MediaVideoPreviewSource): string {
32 return JSON.stringify(
33 "uri" in source
34 ? ["media-video", source.uri]
35 : [
36 "media-video",
37 source.environmentId,
38 source.resource.threadId,
39 source.resource.path,
40 source.srcFragment ?? "",
41 ],
42 );
44​
45export type AttachmentVideoPreviewSource = (
46 | { readonly type: "local"; readonly attachment: DraftComposerFileAttachment }
47 | {
48 readonly type: "remote";
49 readonly environmentId: EnvironmentId;
50 readonly attachment: ChatFileAttachment;
51 }
52) & { readonly sourceIdentifier?: string };
53​
54export type VideoPreviewSource = AttachmentVideoPreviewSource | MediaVideoPreviewSource;