""" HTTP API surface for the rebuilt extension. Registered on ComfyUI's PromptServer (aiohttp). Kept deliberately minimal — routes get added back here piece by piece. Legacy `routes.py` / `civitai_routes.py` are left untouched for reference, not loaded. """ from aiohttp import web from server import PromptServer from . import hashing def setup_routes() -> None: """Register API routes with the running ComfyUI server.""" routes = PromptServer.instance.routes @routes.get("/imagelab/hashes") async def get_hashes(request: web.Request) -> web.Response: """ Return the full model-hash cache in one shot: { "version": "", "models": [ {key, filename, hash, hashed_at}, ... ] } `version` is a content token over every (key, hash) pair. Clients should send it back via `If-None-Match`; when nothing has changed the endpoint replies `304 Not Modified` with no body, so repeat loads are essentially free. The payload itself is served straight from memory — no per-request disk I/O. """ version, entries = hashing.get_snapshot() etag = f'"{version}"' if request.headers.get("If-None-Match") == etag: return web.Response(status=304, headers={"ETag": etag}) return web.json_response( {"version": version, "models": entries}, headers={"ETag": etag, "Cache-Control": "no-cache"}, ) print("[ImageLab] API routes registered")