fix(containers): учитывать фактические состояния контейнеров

This commit is contained in:
Denozordec committed 2026-10-14 18:35:07 +07:00
1 parent 0cc8fe5572
commit b3d11276dd
14 files changed
+357 -14

No files matched your search

@@ -0,0 +1,26 @@
type Status = "running" | "stopped" | "error" | "unknown"
const flags = ["running", "stopped", "error", "failed", "extracting", "downloading", "starting", "stopping"] as const
/** RouterOS REST can expose active flags instead of the legacy status field. */
export function containerRuntimeStatus(row: Record<string, unknown>): Status {
const active = new Set<string>()
for (const flag of flags) {
const value = row[flag]
if (value === undefined) continue
if (value === true || value === "true" || value === "yes") active.add(flag)
else if (value !== false && value !== "false" && value !== "no") return "unknown"
}
if (["extracting", "downloading", "starting", "stopping"].some(flag => active.has(flag))) return "unknown"
const states: Status[] = []
if (active.has("running")) states.push("running")
if (active.has("stopped")) states.push("stopped")
if (active.has("error") || active.has("failed")) states.push("error")
if (states.length > 1) return "unknown"
if (row.status !== undefined) {
if (typeof row.status !== "string") return "unknown"
const value = row.status.toLowerCase()
const legacy = value === "running" || value === "stopped" ? value : value === "error" || value === "failed" ? "error" : "unknown"
if (legacy === "unknown" || (states.length && states[0] !== legacy)) return "unknown"
return legacy
}
return states[0] ?? "unknown"
}