// Job and node labels shared by the dashboard and the Jobs page. import { t, has } from "./i18n.js"; import { escapeHtml, attr, bar } from "./ui.js"; const CODECS = { h264: "H.264", hevc: "HEVC", av1: "AV1" }; /** Hardware encoder families as users know them, recognised in the Media Foundation encoder names. */ const VENDORS = [[/nvidia|nvenc/i, "NVENC"], [/intel|quick ?sync|qsv/i, "QSV"], [/amd|radeon|amf/i, "AMF"]]; export function pascal(text) { return String(text).split(/[-_]/).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join(""); } export function kindLabel(kind) { const key = `Admin.Job.Kind.${pascal(kind)}`; return has(key) ? t(key) : kind; } export function stateLabel(state) { const key = `Admin.Job.State.${pascal(state)}`; return has(key) ? t(key) : state; } /** Where a job runs: this server, a render node by name, or nowhere yet. */ export function nodeLabel(job, nodes) { if (!job.nodeId) return "—"; if (job.nodeId.startsWith("server:")) return t("Admin.Jobs.Server"); return nodes.find((n) => n.id === job.nodeId)?.clientName ?? "—"; } export function progressCell(job) { if (job.progressTotal <= 0) return `
${bar(0, true)}—
`; const fraction = job.progressDone / job.progressTotal; return `
${bar(fraction)}${Math.floor(fraction * 100)} %
`; } export function stateCell(state) { const glyph = { running: "◐", queued: "○", paused: "❚❚", done: "●", failed: "✕", cancelled: "○" }[state] ?? ""; return ` ${escapeHtml(stateLabel(state))}`; } /** The job log: the tail, then the error unless the tail already ends with it. */ export function logText(job) { const tail = (job.logTail ?? "").trimEnd(); return job.error && !tail.endsWith(job.error.trim()) ? `${tail}\n${job.error}`.trim() : tail; } /** Node encoders by family, as "NVENC HEVC/H.264/AV1" (software encoders without a family name). */ export function encoders(node) { const families = new Map(); for (const e of node.encoders) { const family = e.hardware ? VENDORS.find(([pattern]) => pattern.test(e.name))?.[1] ?? "" : ""; const codec = CODECS[e.codec] ?? e.codec.toUpperCase(); const codecs = families.get(family) ?? []; if (!codecs.includes(codec)) codecs.push(codec); families.set(family, codecs); } return [...families].map(([family, codecs]) => `${family} ${codecs.join("/")}`.trim()).join(", "); }