t3xbu10dr: Publish video posts through the media pipeline and upgrade thumbnails to the player

This commit is contained in:
2026-10-19 14:49:03 -06:00
parent b4fb345f90
commit d493b35ede
9 changed files with 181 additions and 19 deletions
+23 -1
View File
@@ -76,7 +76,8 @@ function toMedia(raw: unknown): CardMedia[] {
if (m.mediaType === "video") {
const thumb = str(m.thumbnailUrl);
const hls = muxHlsUrl(m.hlsUrl);
if (thumb || hls) out.push({ kind: "video", src: thumb, hlsUrl: hls });
// Keep a video even with no thumbnail or hlsUrl yet (just published).
out.push({ kind: "video", src: thumb, hlsUrl: hls });
continue;
}
const src = str(m.imageMediumWebpUrl) ?? str(m.imageMediumUrl) ?? str(m.imageUrl);
@@ -142,6 +143,27 @@ export function mergePosts(...lists: CardPost[][]): CardPost[] {
return sortByPublishedDesc(all);
}
const hasHls = (p: CardPost) => p.media.some((m) => m.kind === "video" && m.hlsUrl);
/**
* Swap in the media of shown posts whose video gained an hlsUrl on a refresh
* (transcoding finished), so the thumbnail upgrades to the player in place.
* Returns the same array when nothing changed.
*/
export function upgradeVideos(current: CardPost[], fresh: CardPost[]): CardPost[] {
const byKey = new Map(fresh.map((p) => [p.key, p]));
let changed = false;
const next = current.map((p) => {
const f = byKey.get(p.key);
if (f && !hasHls(p) && hasHls(f)) {
changed = true;
return { ...p, media: f.media };
}
return p;
});
return changed ? next : current;
}
export function relativeTime(publishedAt: string | null, now: number = Date.now()): string {
const t = publishedAt ? Date.parse(publishedAt) : NaN;
if (!Number.isFinite(t)) return "";