Initial commit — ComfyUI Discord bot + web UI
Full source for the-third-rev: Discord bot (discord.py), FastAPI web UI (React/TS/Vite/Tailwind), ComfyUI integration, generation history DB, preset manager, workflow inspector, and all supporting modules. Excluded from tracking: .env, invite_tokens.json, *.db (SQLite), current-workflow-changes.json, user_settings/, presets/, logs/, web-static/ (build output), frontend/node_modules/. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
74
web/routers/status_router.py
Normal file
74
web/routers/status_router.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""GET /api/status — polling fallback for clients that can't use WebSocket"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from web.auth import require_auth
|
||||
from web.deps import get_bot, get_comfy, get_config
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
async def get_status(_: dict = Depends(require_auth)):
|
||||
"""Return a full status snapshot."""
|
||||
bot = get_bot()
|
||||
comfy = get_comfy()
|
||||
config = get_config()
|
||||
|
||||
snap: dict = {}
|
||||
|
||||
if bot is not None:
|
||||
import datetime as _dt
|
||||
lat = bot.latency
|
||||
lat_ms = round(lat * 1000) if (lat is not None and lat != float("inf")) else 0
|
||||
start = getattr(bot, "start_time", None)
|
||||
uptime = ""
|
||||
if start:
|
||||
delta = _dt.datetime.now(_dt.timezone.utc) - start
|
||||
total = int(delta.total_seconds())
|
||||
h, rem = divmod(total, 3600)
|
||||
m, s = divmod(rem, 60)
|
||||
uptime = f"{h}h {m}m {s}s" if h else (f"{m}m {s}s" if m else f"{s}s")
|
||||
snap["bot"] = {"latency_ms": lat_ms, "uptime": uptime}
|
||||
|
||||
if comfy is not None:
|
||||
q_task = asyncio.create_task(comfy.get_comfy_queue())
|
||||
conn_task = asyncio.create_task(comfy.check_connection())
|
||||
q, reachable = await asyncio.gather(q_task, conn_task)
|
||||
|
||||
pending = len(q.get("queue_pending", [])) if q else 0
|
||||
running = len(q.get("queue_running", [])) if q else 0
|
||||
wm = getattr(comfy, "workflow_manager", None)
|
||||
wf_loaded = wm is not None and wm.get_workflow_template() is not None
|
||||
|
||||
snap["comfy"] = {
|
||||
"server": comfy.server_address,
|
||||
"reachable": reachable,
|
||||
"queue_pending": pending,
|
||||
"queue_running": running,
|
||||
"workflow_loaded": wf_loaded,
|
||||
"last_seed": comfy.last_seed,
|
||||
"total_generated": comfy.total_generated,
|
||||
}
|
||||
snap["overrides"] = comfy.state_manager.get_overrides()
|
||||
|
||||
if config is not None:
|
||||
from commands.server import get_service_state
|
||||
service_state = await get_service_state(config.comfy_service_name)
|
||||
snap["service"] = {"state": service_state}
|
||||
|
||||
try:
|
||||
from media_uploader import get_stats as us_fn, is_running as ur_fn
|
||||
us = us_fn()
|
||||
snap["upload"] = {
|
||||
"configured": bool(config.media_upload_user),
|
||||
"running": ur_fn(),
|
||||
"total_ok": us.total_ok,
|
||||
"total_fail": us.total_fail,
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return snap
|
||||
Reference in New Issue
Block a user