Fix Pro config SSOT, event FSM, FFmpeg error tiers, relay heartbeat, and ingest auth while keeping relay snapshot, quality guard, and event hub hidden in the UI. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
export function formatUptime(sec?: number) {
|
|
if (sec == null || !Number.isFinite(sec)) return "—";
|
|
const s = Math.max(0, Math.floor(sec));
|
|
const d = Math.floor(s / 86400);
|
|
const h = Math.floor((s % 86400) / 3600);
|
|
const m = Math.floor((s % 3600) / 60);
|
|
if (d > 0) return `${d}d ${h}h`;
|
|
if (h > 0) return `${h}h ${m}m`;
|
|
return `${m}m`;
|
|
}
|
|
|
|
export function formatBytes(value?: number) {
|
|
if (value == null || !Number.isFinite(value)) return "—";
|
|
if (value === 0) return "0 B";
|
|
const u = ["B", "KB", "MB", "GB", "TB"];
|
|
let n = value;
|
|
let i = 0;
|
|
while (n >= 1024 && i < u.length - 1) {
|
|
n /= 1024;
|
|
i += 1;
|
|
}
|
|
return `${n.toFixed(n >= 10 || i === 0 ? 0 : 1)} ${u[i]}`;
|
|
}
|
|
|
|
export function formatRate(value?: number) {
|
|
const text = formatBytes(value);
|
|
return text === "—" ? text : `${text}/s`;
|
|
}
|
|
|
|
export function formatPercent(used: number, total: number) {
|
|
if (!total || !Number.isFinite(used) || !Number.isFinite(total)) return 0;
|
|
return Math.min(100, Math.max(0, Math.round((used / total) * 100)));
|
|
}
|
|
|
|
export function statusPill(status: string) {
|
|
if (status === "online" || status === "running" || status === "streaming")
|
|
return "bg-emerald-500/15 text-emerald-300 ring-1 ring-emerald-500/30";
|
|
if (status === "configured") return "bg-sky-500/15 text-sky-200 ring-1 ring-sky-500/25";
|
|
if (status === "skipped") return "bg-slate-500/15 text-slate-300 ring-1 ring-slate-500/30";
|
|
if (status === "stopped" || status === "not_found")
|
|
return "bg-zinc-500/15 text-zinc-400 ring-1 ring-zinc-500/25";
|
|
if (status === "error") return "bg-rose-500/15 text-rose-300 ring-1 ring-rose-500/35";
|
|
return "bg-violet-500/15 text-violet-200 ring-1 ring-violet-500/30";
|
|
}
|
|
|
|
export function statusLabel(status: string, t: (zh: string, en: string) => string) {
|
|
const normalized = (status || "").trim().toLowerCase();
|
|
if (normalized === "online" || normalized === "running" || normalized === "streaming") return t("运行中", "Running");
|
|
if (normalized === "configured") return t("已配置", "Configured");
|
|
if (normalized === "not_found") return t("未注册", "Unregistered");
|
|
if (normalized === "stopped") return t("已停止", "Stopped");
|
|
if (normalized === "error") return t("异常", "Error");
|
|
return status || "—";
|
|
}
|