/** * health.js — Проверка доступности сервера обработки ComfyUI */ export function setHealthState(state, message, title = "") { const healthStatus = document.querySelector("#health-status"); const healthText = document.querySelector("#health-text"); if (!healthStatus || !healthText) return; healthStatus.className = `health-status health-${state}`; healthStatus.title = title || message; healthText.textContent = message; } export async function checkHealth() { try { const response = await fetch("/api/health"); if (!response.ok) { setHealthState("error", "Сервер обработки недоступен"); return; } const data = await response.json(); if (!data.comfyAvailable) { setHealthState("error", data.message || "ComfyUI недоступен"); return; } const missing = data.missingNodes || []; if (missing.length > 0) { setHealthState( "warn", "Не хватает узлов ComfyUI", `Отсутствуют узлы: ${missing.join(", ")}` ); return; } setHealthState("ok", "Сервер обработки готов"); } catch { setHealthState("error", "Не удалось проверить сервер обработки"); } } export function startHealthPolling(intervalMs = 30000) { checkHealth(); return setInterval(checkHealth, intervalMs); }