Archived
Clean-slate rebuild. The previous entrypoint and modules (routes.py, workflows.py, imagelab_nodes.py, resources.py, etc.) are kept for reference as __init__.py.legacy + untouched files, not loaded. New surface: - hashing.py: SHA256 model hashing keyed by path relative to the models dir (no more bare-filename collisions). .index sidecars under model_index/. Maintains an in-memory index + ETag-style version token. - api.py: GET /imagelab/hashes serves the full cache from memory in one request, with ETag/If-None-Match -> 304 support. - __init__.py: registers the API and builds the hash index in a background thread on startup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""
|
|
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": "<etag>", "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")
|