Files
siftlode/frontend/src/components/downloadTitle.ts
T
peter 098b8dbe43 feat(downloads): a bare link is titled once, a missing picture shows a glyph
A job with no name yet is titled by its short link, as the link itself;
the channel line no longer falls back to the ref and the link line does
not repeat it. No picture at all draws a film (or note) glyph instead of
an empty box.
2026-09-27 07:12:51 +02:00

29 lines
1.1 KiB
TypeScript

import type { DownloadJob } from "../lib/api";
// A download job's display title (a user rename wins over the extracted asset title), shared by the
// row, the admin list and the library player. Its own module so downloadRow exports only components.
// 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)
);
}
/** The job has a name of its own (a rename or an extracted title), not the link standing in for one. */
export function hasOwnTitle(job: DownloadJob): boolean {
return !!(job.display_name || job.asset?.title);
}
// Compact display of a URL: drop the protocol + trailing slash so "youtube.com/watch?v=…" fits.
export function displayUrl(url: string): string {
try {
const u = new URL(url);
return (u.host + u.pathname + u.search).replace(/\/$/, "");
} catch {
return url;
}
}