import { api } from "../api.js"; import { emptyState, sectionHeader } from "../components.js"; import { escapeHtml, formatCount, formatDateTime, formatNumber, } from "../format.js"; function taskRows(tasks) { const entries = Object.entries(tasks || {}); if (!entries.length) return emptyState("暂无任务记录", "运行一次同步、快照或发现后会写入最近结果。"); return `
${entries.map(([name, record]) => { const summary = record.summary && typeof record.summary === "object" ? Object.entries(record.summary) .filter(([key]) => ["added", "removed", "candidates", "notified", "ok", "failed", "total", "completed", "backup_error"].includes(key)) .map(([key, value]) => `${key}=${value}`).join(" ") : ""; return ``; }).join("")}
任务结果完成时间摘要 / 错误
${escapeHtml(name)} ${record.ok ? "成功" : `失败`} ${escapeHtml(formatDateTime(record.finished_at))} ${escapeHtml(summary || record.error || "—")}
`; } export async function renderSystem(root) { const system = await api("/api/system"); const health = system.snapshot_health || { total: 0, ok: 0, failed: 0 }; const counts = system.counts || {}; const next = system.next_runs || {}; root.innerHTML = `

系统状态

数据 ${escapeHtml(system.data_date || "—")} · 快照 ${formatCount(system.snapshot_days)} 天

采集成功${formatCount(health.ok)}
采集失败${formatCount(health.failed)}
在库${formatCount(counts.active)}
已取消收藏${formatCount(counts.unfaved)}
已失效${formatCount(counts.removed)}
已移出库${formatCount(counts.dropped)}
${sectionHeader("最近任务")} ${taskRows(system.tasks)}
${sectionHeader("预计下次运行")}
收藏夹同步${escapeHtml(formatDateTime(next.folder_sync))}
搜索发现${escapeHtml(formatDateTime(next.discover))}
每日快照${escapeHtml(formatDateTime(next.snapshot))}
调度参数${system.schedule.discover_minutes} / ${system.schedule.folder_sync_minutes} 分钟

预计时间按配置和最近任务完成时间推算;实际以常驻进程为准。

${sectionHeader("收藏夹容量")} ${(system.folders || []).map((folder) => `
${escapeHtml(folder.title || String(folder.year))} ${formatCount(folder.media_count)} / ${formatCount(folder.capacity)}

最近同步 ${escapeHtml(formatDateTime(folder.last_ids_at))}

`).join("") || emptyState("未配置收藏夹")}
${sectionHeader("授权与备份")}
登录态${system.auth.ok === "1" ? "正常" : "异常"}
登录信息${escapeHtml(system.auth.message || "—")}
最近检查${escapeHtml(formatDateTime(system.auth.last_check))}
最近备份${system.backup.ok === "1" ? "成功" : "未完成"}
备份错误${escapeHtml(system.backup.error || "—")}
Telegram${system.telegram_enabled ? "已启用" : "未启用"}
${(system.errors || []).length ? `
${sectionHeader("最近错误")} ${system.errors.map((error) => `
${escapeHtml(error.task)} ${escapeHtml(error.error || "未知错误")}
`).join("")}
` : ""}
${sectionHeader("UP 黑名单")}

只影响未来搜索发现;已入库视频继续追踪。移除请使用 CLI 或数据库。

${(system.blacklist || []).length ? `
${system.blacklist.map((item) => ``).join("")}
mid昵称原因在库视频
${item.mid} ${escapeHtml(item.name || "—")} ${escapeHtml(item.reason || "—")} ${formatNumber(item.video_count || 0)}
` : emptyState("黑名单为空")}
`; }