Files
comfy-discord-web/web/deps.py
Khoa (Revenovich) Tran Gia 1ed3c9ec4b 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>
2026-03-02 09:55:48 +07:00

73 lines
1.6 KiB
Python

"""
web/deps.py
===========
Shared bot reference for FastAPI dependency injection.
``set_bot()`` is called once from ``bot.py`` before starting Uvicorn.
FastAPI route handlers use ``get_bot()``, ``get_comfy()``, etc. as
Depends() callables.
"""
from __future__ import annotations
from typing import Optional
_bot = None
def set_bot(bot) -> None:
"""Store the discord.py bot instance for DI access."""
global _bot
_bot = bot
def get_bot():
"""FastAPI dependency: return the bot instance."""
return _bot
def get_comfy():
"""FastAPI dependency: return the ComfyClient."""
if _bot is None:
return None
return getattr(_bot, "comfy", None)
def get_config():
"""FastAPI dependency: return the BotConfig."""
if _bot is None:
return None
return getattr(_bot, "config", None)
def get_state_manager():
"""FastAPI dependency: return the WorkflowStateManager."""
comfy = get_comfy()
if comfy is None:
return None
return getattr(comfy, "state_manager", None)
def get_workflow_manager():
"""FastAPI dependency: return the WorkflowManager."""
comfy = get_comfy()
if comfy is None:
return None
return getattr(comfy, "workflow_manager", None)
def get_inspector():
"""FastAPI dependency: return the WorkflowInspector."""
comfy = get_comfy()
if comfy is None:
return None
return getattr(comfy, "inspector", None)
def get_user_registry():
"""FastAPI dependency: return the UserStateRegistry."""
if _bot is None:
return None
return getattr(_bot, "user_registry", None)