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/routes.py
T
2026-01-03 14:42:05 -07:00

62 lines
1.9 KiB
Python

"""
API routes for external workflow execution.
"""
from aiohttp import web
from server import PromptServer
from .workflows import get_workflow, list_workflows
def SetupRoutes(server: PromptServer):
"""Register API routes with the ComfyUI server."""
@server.instance.routes.get("/external-api/workflows")
async def list_available_workflows(request):
"""List all available workflows."""
return web.json_response({
'workflows': list_workflows()
})
@server.instance.routes.post("/external-api/workflow/{workflow_name}")
async def execute_workflow(request):
"""Execute a specific workflow by name."""
workflow_name = request.match_info['workflow_name']
try:
# Get the workflow function
workflow_func = get_workflow(workflow_name)
# Parse request body for parameters
try:
params = await request.json()
except:
params = {}
# Execute workflow
result = workflow_func(**params)
return web.json_response({
'success': True,
'workflow': workflow_name,
'result': result
})
except ValueError as e:
return web.json_response({
'success': False,
'type': 'ValueError',
'error': str(e)
}, status=404)
except Exception as e:
return web.json_response({
'success': False,
'type': 'Exception',
'error': f"Workflow execution failed: {str(e)}"
}, status=500)
@server.instance.routes.get("/external-api/hello")
async def get_hello(request):
"""Test endpoint."""
return web.json_response({
'message': 'Hello from external API!'
})