-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
60 lines (48 loc) · 2.1 KB
/
Copy path__init__.py
File metadata and controls
60 lines (48 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import json
from server import PromptServer
from aiohttp import web
import folder_paths
WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {}
import asyncio
# Global in-memory registry
_workflow_registry = {"nodes": {}, "update_event": asyncio.Event()}
# Add a redirect route for /gallery
@PromptServer.instance.routes.get("/gallery")
async def gallery_redirect(request):
raise web.HTTPFound("/extensions/comfyui-local-gallery/index.html")
# Add an API to get the current output directory path
@PromptServer.instance.routes.get("/api/gallery/output_path")
async def get_output_path(request):
return web.json_response({"path": os.path.abspath(folder_paths.get_output_directory())})
@PromptServer.instance.routes.post("/api/gallery/register-nodes")
async def register_nodes(request):
try:
data = await request.json()
nodes = data.get("nodes", [])
registry = {}
for node in nodes:
node_id = node.get("node_id")
if node_id is not None:
registry[str(node_id)] = node
_workflow_registry["nodes"] = registry
_workflow_registry["update_event"].set()
_workflow_registry["update_event"].clear()
return web.json_response({"success": True})
except Exception as e:
return web.json_response({"success": False, "error": str(e)}, status=500)
@PromptServer.instance.routes.get("/api/gallery/get-registry")
async def get_registry(request):
try:
# Trigger a refresh from the frontend
PromptServer.instance.send_sync("gallery_registry_refresh", {})
# Wait for the frontend to report back (timeout 2s)
try:
await asyncio.wait_for(_workflow_registry["update_event"].wait(), timeout=2.0)
except asyncio.TimeoutError:
pass # Return whatever we have if it times out
return web.json_response({"success": True, "nodes": _workflow_registry["nodes"]})
except Exception as e:
return web.json_response({"success": False, "error": str(e)}, status=500)
__all__ = ["WEB_DIRECTORY", "NODE_CLASS_MAPPINGS"]