Files
x0x0b-ComfyUI-PromptHistory…/__init__.py
T
x0x0b 8650c3da82 feat: add code formatter (#22)
* feat: add CI configuration for code formatting and linting

* style: apply consistent formatting

* fix

* fix

* style: update formatting instructions for Python and web assets

* feat: add script for automated code formatting with Ruff and Prettier

* fix: update Ruff dependency version in pyproject.toml
2025-12-17 08:22:01 +09:00

66 lines
1.8 KiB
Python

"""
Entry point for ComfyUI to discover the Prompt History Gallery nodes.
"""
from aiohttp import web
from server import PromptServer
from .prompt_history_gallery import (
NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS,
get_prompt_history_storage,
)
WEB_DIRECTORY = "./web"
__all__ = [
"NODE_CLASS_MAPPINGS",
"NODE_DISPLAY_NAME_MAPPINGS",
"WEB_DIRECTORY",
]
def _serialize_entry(entry):
payload = entry.to_dict()
if not isinstance(payload.get("files"), list):
payload["files"] = []
return payload
def _get_limit(request, *, default=50, minimum=20, maximum=1000):
value = request.rel_url.query.get("limit")
if value is None:
return max(minimum, min(default, maximum))
try:
limit = int(value)
except (TypeError, ValueError):
return max(minimum, min(default, maximum))
return max(minimum, min(limit, maximum))
@PromptServer.instance.routes.get("/prompt-history")
async def list_prompt_history(request):
storage = get_prompt_history_storage()
limit = _get_limit(request)
entries = [_serialize_entry(entry) for entry in storage.list(limit=limit)]
return web.json_response({"entries": entries})
@PromptServer.instance.routes.delete("/prompt-history/{entry_id}")
async def delete_prompt_history_entry(request):
entry_id = request.match_info.get("entry_id")
if not entry_id:
raise web.HTTPBadRequest()
storage = get_prompt_history_storage()
deleted = storage.delete(entry_id)
if not deleted:
raise web.HTTPNotFound()
return web.json_response({"ok": True})
@PromptServer.instance.routes.delete("/prompt-history")
async def clear_prompt_history(request):
storage = get_prompt_history_storage()
storage.clear()
return web.json_response({"ok": True})