This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagelab_v3_extension/__init__.py
T
donnyandClaude Opus 4.7 496f613b6a Add CivitAI downloads + local model deletion, with startup auto-download
downloads.py: streamed CivitAI downloads into the right ComfyUI folder,
in-memory progress (polled), cancel, and local model deletion. Adapted
from the legacy civitai.py — trimmed to download/cancel/delete and wired
into the new hash index:
- destination folder is derived from CivitAI's model type unless forced
- finished downloads are hashed into the index (shows in /imagelab/hashes)
- deletes drop the model from the index via hashing.forget()
- skip-if-present so persistent-volume pods don't re-download
- IMAGELAB_AUTO_DOWNLOAD env var: comma/newline list of version ids,
  CivitAI URLs, model:<id>, or <folder>::<entry> — queued on startup

api.py: POST/GET/DELETE /imagelab/downloads + DELETE /imagelab/models/...
hashing.py: forget() — remove a model's .index sidecar + in-memory entry
__init__.py: queue startup downloads via the aiohttp on_startup hook

Token via CIVITAI_TOKEN env var. Legacy civitai*.py / websocket.py left
untouched as reference.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 15:57:53 -07:00

61 lines
2.0 KiB
Python

"""
ImageLab v3 — ComfyUI custom node entrypoint.
This is a clean-slate rebuild. So far it:
- hashes all model files on startup (background) into an index
- exposes that index + CivitAI download/delete over a small HTTP API
- optionally auto-downloads models on startup (IMAGELAB_AUTO_DOWNLOAD)
Functionality is added back in pieces. The previous entrypoint is preserved
as `__init__.py.legacy`, alongside the other legacy modules (`routes.py`,
`workflows.py`, `imagelab_nodes.py`, `resources.py`, ...) — kept for
reference, not loaded.
"""
import threading
from server import PromptServer
from . import hashing
from . import api
from . import downloads
# No custom nodes yet — ComfyUI still expects these symbols to exist.
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
# Register the HTTP API (synchronous — routes must exist before the server
# finishes starting; this is just dict insertion, it does not block).
api.setup_routes()
def _hash_on_startup():
print("[ImageLab] Building model-hash index in the background ...")
try:
counts = hashing.build_index()
if counts:
print(f"[ImageLab] Hashed: {counts}")
else:
print("[ImageLab] No new models to hash")
version, entries = hashing.get_snapshot()
print(f"[ImageLab] Index ready: {len(entries)} models (version {version})")
except Exception as e:
print(f"[ImageLab] Error during startup hashing: {e}")
threading.Thread(target=_hash_on_startup, daemon=True).start()
async def _auto_download_on_startup(_app):
"""aiohttp on_startup hook — runs inside the server loop, so downloads
(which create asyncio tasks) can be queued safely."""
try:
await downloads.queue_startup_downloads()
except Exception as e:
print(f"[ImageLab] Error queueing startup downloads: {e}")
# Defer auto-downloads until the server's event loop is running.
PromptServer.instance.app.on_startup.append(_auto_download_on_startup)
print("[ImageLab] v3 loaded")