feat: support new frontend!

This commit is contained in:
bennykok 2024-08-14 11:09:58 -07:00
parent f6ea252652
commit 10268825d9
3 changed files with 1203 additions and 1041 deletions

View File

@ -17,12 +17,13 @@ from urllib.parse import quote
import threading import threading
import hashlib import hashlib
import aiohttp import aiohttp
from aiohttp import ClientSession, web
import aiofiles import aiofiles
from typing import Dict, List, Union, Any, Optional from typing import Dict, List, Union, Any, Optional
from PIL import Image from PIL import Image
import copy import copy
import struct import struct
from aiohttp import ClientError from aiohttp import web, ClientSession, ClientError
import atexit import atexit
# Global session # Global session
@ -836,6 +837,50 @@ async def send(event, data, sid=None):
logger.info(f"Exception: {e}") logger.info(f"Exception: {e}")
traceback.print_exc() traceback.print_exc()
@server.PromptServer.instance.routes.get('/comfydeploy/{tail:.*}')
@server.PromptServer.instance.routes.post('/comfydeploy/{tail:.*}')
async def proxy_to_comfydeploy(request):
# Get the base URL
base_url = f'https://www.comfydeploy.com/{request.match_info["tail"]}'
# Get all query parameters
query_params = request.query_string
# Construct the full target URL with query parameters
target_url = f"{base_url}?{query_params}" if query_params else base_url
print(f"Proxying request to: {target_url}")
try:
# Create a new ClientSession for each request
async with ClientSession() as client_session:
# Forward the request
client_req = await client_session.request(
method=request.method,
url=target_url,
headers={k: v for k, v in request.headers.items() if k.lower() not in ('host', 'content-length')},
data=await request.read(),
allow_redirects=False,
)
# Read the entire response content
content = await client_req.read()
# Try to decode the content as JSON
try:
json_data = json.loads(content)
# If successful, return a JSON response
return web.json_response(json_data, status=client_req.status)
except json.JSONDecodeError:
# If it's not valid JSON, return the content as-is
return web.Response(body=content, status=client_req.status, headers=client_req.headers)
except ClientError as e:
print(f"Client error occurred while proxying request: {str(e)}")
return web.Response(status=502, text=f"Bad Gateway: {str(e)}")
except Exception as e:
print(f"Error occurred while proxying request: {str(e)}")
return web.Response(status=500, text=f"Internal Server Error: {str(e)}")
prompt_server = server.PromptServer.instance prompt_server = server.PromptServer.instance

View File

@ -2,4 +2,5 @@ aiofiles
pydantic pydantic
opencv-python opencv-python
imageio-ffmpeg imageio-ffmpeg
brotli
# logfire # logfire

File diff suppressed because it is too large Load Diff