mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
import asyncio
|
|
from server import PromptServer # type: ignore
|
|
from .config import config
|
|
from .routes.lora_routes import LoraRoutes
|
|
from .routes.api_routes import ApiRoutes
|
|
from .services.lora_scanner import LoraScanner
|
|
|
|
class LoraManager:
|
|
"""Main entry point for LoRA Manager plugin"""
|
|
|
|
@classmethod
|
|
def add_routes(cls):
|
|
"""Initialize and register all routes"""
|
|
app = PromptServer.instance.app
|
|
|
|
# Add static routes for each lora root
|
|
for idx, root in enumerate(config.loras_roots, start=1):
|
|
preview_path = f'/loras_static/root{idx}/preview'
|
|
app.router.add_static(preview_path, root)
|
|
|
|
# Add static route for plugin assets
|
|
app.router.add_static('/loras_static', config.static_path)
|
|
|
|
# Setup feature routes
|
|
routes = LoraRoutes()
|
|
api_routes = ApiRoutes()
|
|
|
|
LoraRoutes.setup_routes(app)
|
|
ApiRoutes.setup_routes(app)
|
|
|
|
# Schedule cache initialization using the application's startup handler
|
|
app.on_startup.append(lambda app: cls._schedule_cache_init(routes.scanner))
|
|
|
|
@classmethod
|
|
async def _schedule_cache_init(cls, scanner: LoraScanner):
|
|
"""Schedule cache initialization in the running event loop"""
|
|
try:
|
|
# Create the initialization task
|
|
asyncio.create_task(cls._initialize_cache(scanner))
|
|
except Exception as e:
|
|
print(f"LoRA Manager: Error scheduling cache initialization: {e}")
|
|
|
|
@classmethod
|
|
async def _initialize_cache(cls, scanner: LoraScanner):
|
|
"""Initialize cache in background"""
|
|
try:
|
|
await scanner.get_cached_data(force_refresh=True)
|
|
print("LoRA Manager: Cache initialization completed")
|
|
except Exception as e:
|
|
print(f"LoRA Manager: Error initializing cache: {e}") |