14oqjtsnb: Play trending video answers as video with thumbnail fallback

This commit is contained in:
2026-10-19 17:40:44 -06:00
parent 77f0dd09a4
commit 31fdc41f23
6 changed files with 111 additions and 21 deletions
+26 -10
View File
@@ -17,16 +17,22 @@ export interface DiscoverExpert {
location: { city: string | null; country: string | null };
}
export type DiscoverMediaKind = "video" | "audio";
export interface DiscoverMedia {
kind: DiscoverMediaKind;
url: string;
duration: number | null;
waveform: number[] | string | null;
}
export interface DiscoverMinnect {
id: string | number;
question: string | null;
views: number | null;
thumbnailUrl: string | null;
audio: {
url: string | null;
duration: number | null;
waveform: number[] | string | null;
};
/** null when the answer has no playable url. */
media: DiscoverMedia | null;
expert: {
slug: string | null;
displayName: string;
@@ -92,6 +98,20 @@ function waveform(v: unknown): number[] | string | null {
return str(v);
}
const VIDEO_TYPES = new Set(["MOV", "MP4", "M4V", "QUICKTIME", "MO4", "WEBM"]);
function mapMedia(answer: Rec): DiscoverMedia | null {
const url = str(answer.url);
if (!url) return null;
const type = (str(answer.file_type) ?? "").trim().toUpperCase();
return {
kind: VIDEO_TYPES.has(type) ? "video" : "audio",
url,
duration: num(answer.duration),
waveform: waveform(answer.waveform_data),
};
}
export function mapMinnect(raw: unknown): DiscoverMinnect | null {
const r = rec(raw);
const mid = id(r.id);
@@ -103,11 +123,7 @@ export function mapMinnect(raw: unknown): DiscoverMinnect | null {
question: str(r.question_text),
views: num(r.views),
thumbnailUrl: str(rec(r.thumbnail).url),
audio: {
url: str(answer.url),
duration: num(answer.duration),
waveform: waveform(answer.waveform_data),
},
media: mapMedia(answer),
expert: {
slug: str(expert.slug),
displayName: displayName(expert),