import type { DownloadJob } from "../lib/api"; // A download job's display title (a user rename wins over the extracted asset title), shared by the // tray, the Files list, the admin Storage tab and the library player. // With no name yet — a link queued before its details arrive, or one that failed first — it is the // link itself, shortened the way the row shows a link, never the raw ref (a URL, or a bare video id). export function jobTitle(job: DownloadJob): string { return ( job.display_name || job.asset?.title || (job.source_url ? displayUrl(job.source_url) : job.source_ref) ); } // Compact display of a URL: drop the protocol + trailing slash so "youtube.com/watch?v=…" fits. function displayUrl(url: string): string { try { const u = new URL(url); return (u.host + u.pathname + u.search).replace(/\/$/, ""); } catch { return url; } }