Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7fb688522 | ||
|
|
b98ae10a76 | ||
|
|
b79ed40f6d | ||
|
|
06ae3af5d0 | ||
|
|
967709dd07 | ||
|
|
07a827d56b | ||
|
|
7f6eea361e | ||
|
|
14829a2b12 | ||
|
|
03c4e2d85d | ||
|
|
bad8b1104f | ||
|
|
ac8779dc54 | ||
|
|
2a5223f2f0 | ||
|
|
f02aef4cb3 | ||
|
|
22458a1cd6 | ||
|
|
0a58eba554 | ||
|
|
def54df9c2 | ||
|
|
32a950afe8 | ||
|
|
8130779d94 | ||
|
|
4cbd2a8225 | ||
|
|
d6fb2daeff | ||
|
|
a91effe3c8 | ||
|
|
c015b710fe | ||
|
|
2738d1913a | ||
|
|
3f4c11e3f1 | ||
|
|
089bad5560 | ||
|
|
46010e1dd5 | ||
|
|
52d876fa67 | ||
|
|
f7e7eb19d0 | ||
|
|
cb03b6718e | ||
|
|
7b734c415a | ||
|
|
64d3ec6b45 | ||
|
|
c47865ec26 |
@@ -0,0 +1,54 @@
|
|||||||
|
class ComfyUIDeployExternalNumberSliderInt:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"input_id": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": "input_number_slider_int"},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"default_value": (
|
||||||
|
"INT",
|
||||||
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 1, "step": 1},
|
||||||
|
),
|
||||||
|
"min_value": (
|
||||||
|
"INT",
|
||||||
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 0, "step": 1},
|
||||||
|
),
|
||||||
|
"max_value": (
|
||||||
|
"INT",
|
||||||
|
{"multiline": True, "display": "number", "min": -2147483647, "max": 2147483647, "default": 10, "step": 1},
|
||||||
|
),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("INT",)
|
||||||
|
RETURN_NAMES = ("value",)
|
||||||
|
FUNCTION = "run"
|
||||||
|
CATEGORY = "🔗ComfyDeploy"
|
||||||
|
|
||||||
|
def run(self, input_id, default_value=None, min_value=0, max_value=10, display_name=None, description=None):
|
||||||
|
try:
|
||||||
|
int_value = int(round(float(input_id)))
|
||||||
|
if min_value <= int_value <= max_value:
|
||||||
|
print("my integer", int_value)
|
||||||
|
return [int_value]
|
||||||
|
else:
|
||||||
|
print("Integer out of range. Returning default value:", default_value)
|
||||||
|
return [default_value]
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
print("Invalid input. Returning default value:", default_value)
|
||||||
|
return [default_value]
|
||||||
|
|
||||||
|
NODE_CLASS_MAPPINGS = {"ComfyUIDeployExternalNumberSliderInt": ComfyUIDeployExternalNumberSliderInt}
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyUIDeployExternalNumberSliderInt": "External Number Slider Int (ComfyUI Deploy)"}
|
||||||
@@ -748,36 +748,64 @@ class ComfyUIDeployExternalVideo:
|
|||||||
file_parts = f.split(".")
|
file_parts = f.split(".")
|
||||||
if len(file_parts) > 1 and (file_parts[-1] in video_extensions):
|
if len(file_parts) > 1 and (file_parts[-1] in video_extensions):
|
||||||
files.append(f)
|
files.append(f)
|
||||||
return {"required": {
|
return {
|
||||||
"input_id": (
|
"required": {
|
||||||
"STRING",
|
"input_id": (
|
||||||
{"multiline": False, "default": "input_video"},
|
"STRING",
|
||||||
),
|
{"multiline": False, "default": "input_video"},
|
||||||
"force_rate": ("INT", {"default": 0, "min": 0, "max": 60, "step": 1}),
|
),
|
||||||
"force_size": (["Disabled", "Custom Height", "Custom Width", "Custom", "256x?", "?x256", "256x256", "512x?", "?x512", "512x512"],),
|
"force_rate": ("INT", {"default": 0, "min": 0, "max": 60, "step": 1}),
|
||||||
"custom_width": ("INT", {"default": 512, "min": 0, "max": DIMMAX, "step": 8}),
|
"force_size": (
|
||||||
"custom_height": ("INT", {"default": 512, "min": 0, "max": DIMMAX, "step": 8}),
|
[
|
||||||
"frame_load_cap": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
|
"Disabled",
|
||||||
"skip_first_frames": ("INT", {"default": 0, "min": 0, "max": BIGMAX, "step": 1}),
|
"Custom Height",
|
||||||
"select_every_nth": ("INT", {"default": 1, "min": 1, "max": BIGMAX, "step": 1}),
|
"Custom Width",
|
||||||
},
|
"Custom",
|
||||||
"optional": {
|
"256x?",
|
||||||
"meta_batch": ("VHS_BatchManager",),
|
"?x256",
|
||||||
"vae": ("VAE",),
|
"256x256",
|
||||||
"default_video": (sorted(files),),
|
"512x?",
|
||||||
"display_name": (
|
"?x512",
|
||||||
"STRING",
|
"512x512",
|
||||||
{"multiline": False, "default": ""},
|
],
|
||||||
),
|
),
|
||||||
"description": (
|
"custom_width": (
|
||||||
"STRING",
|
"INT",
|
||||||
{"multiline": True, "default": ""},
|
{"default": 512, "min": 0, "max": DIMMAX, "step": 8},
|
||||||
),
|
),
|
||||||
},
|
"custom_height": (
|
||||||
"hidden": {
|
"INT",
|
||||||
"unique_id": "UNIQUE_ID"
|
{"default": 512, "min": 0, "max": DIMMAX, "step": 8},
|
||||||
},
|
),
|
||||||
}
|
"frame_load_cap": (
|
||||||
|
"INT",
|
||||||
|
{"default": 0, "min": 0, "max": BIGMAX, "step": 1},
|
||||||
|
),
|
||||||
|
"skip_first_frames": (
|
||||||
|
"INT",
|
||||||
|
{"default": 0, "min": 0, "max": BIGMAX, "step": 1},
|
||||||
|
),
|
||||||
|
"select_every_nth": (
|
||||||
|
"INT",
|
||||||
|
{"default": 1, "min": 1, "max": BIGMAX, "step": 1},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"meta_batch": ("VHS_BatchManager",),
|
||||||
|
"vae": ("VAE",),
|
||||||
|
"default_video": (sorted(files),),
|
||||||
|
"display_name": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": False, "default": ""},
|
||||||
|
),
|
||||||
|
"description": (
|
||||||
|
"STRING",
|
||||||
|
{"multiline": True, "default": ""},
|
||||||
|
),
|
||||||
|
"default_value_url": ("STRING", {"image_preview": True, "default": ""}),
|
||||||
|
},
|
||||||
|
"hidden": {"unique_id": "UNIQUE_ID"},
|
||||||
|
}
|
||||||
|
|
||||||
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
CATEGORY = "Video Helper Suite 🎥🅥🅗🅢"
|
||||||
|
|
||||||
@@ -804,16 +832,21 @@ class ComfyUIDeployExternalVideo:
|
|||||||
select_every_nth = kwargs.get("select_every_nth")
|
select_every_nth = kwargs.get("select_every_nth")
|
||||||
meta_batch = kwargs.get("meta_batch")
|
meta_batch = kwargs.get("meta_batch")
|
||||||
unique_id = kwargs.get("unique_id")
|
unique_id = kwargs.get("unique_id")
|
||||||
|
default_value_url = kwargs.get("default_value_url")
|
||||||
|
|
||||||
input_dir = folder_paths.get_input_directory()
|
input_dir = folder_paths.get_input_directory()
|
||||||
if input_id.startswith("http"):
|
if input_id.startswith("http") or (
|
||||||
|
default_value_url and default_value_url.startswith("http")
|
||||||
|
):
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
print("Fetching video from URL: ", input_id)
|
# Use input_id if it's a URL, otherwise use default_value_url
|
||||||
response = requests.get(input_id, stream=True)
|
url = input_id if input_id.startswith("http") else default_value_url
|
||||||
|
|
||||||
|
print("Fetching video from URL: ", url)
|
||||||
|
response = requests.get(url, stream=True)
|
||||||
file_size = int(response.headers.get("Content-Length", 0))
|
file_size = int(response.headers.get("Content-Length", 0))
|
||||||
file_extension = input_id.split(".")[-1].split("?")[
|
file_extension = url.split(".")[-1].split("?")[
|
||||||
0
|
0
|
||||||
] # Extract extension and handle URLs with parameters
|
] # Extract extension and handle URLs with parameters
|
||||||
if file_extension not in video_extensions:
|
if file_extension not in video_extensions:
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# In file: comfyui-deploy/comfy-nodes/output_exr.py
|
||||||
|
|
||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
import folder_paths
|
||||||
|
|
||||||
|
# Try to set up OpenCV for EXR writing.
|
||||||
|
try:
|
||||||
|
os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
|
||||||
|
import cv2
|
||||||
|
OPENCV_AVAILABLE = True
|
||||||
|
except ImportError:
|
||||||
|
print("Warning: OpenCV not found for ComfyDeployOutputEXR. Please add opencv-python-headless to requirements.txt")
|
||||||
|
OPENCV_AVAILABLE = False
|
||||||
|
|
||||||
|
# ALIGNED: Renamed class to match project conventions
|
||||||
|
class ComfyDeployOutputEXR:
|
||||||
|
def __init__(self):
|
||||||
|
self.output_dir = folder_paths.get_output_directory()
|
||||||
|
self.type = "output"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"images": ("IMAGE", ),
|
||||||
|
"filename_prefix": ("STRING", {"default": "ComfyDeploy_EXR"})
|
||||||
|
},
|
||||||
|
# ADDED: Optional output_id for consistency with other ComfyDeploy nodes
|
||||||
|
"optional": {
|
||||||
|
"output_id": ("STRING", {"multiline": False, "default": "output_exr"}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ()
|
||||||
|
# ALIGNED: Changed function name to 'run'
|
||||||
|
FUNCTION = "run"
|
||||||
|
OUTPUT_NODE = True
|
||||||
|
# ALIGNED: Matched the category name
|
||||||
|
CATEGORY = "🔗ComfyDeploy"
|
||||||
|
DESCRIPTION = "Saves the input images as EXR (HDR) files."
|
||||||
|
|
||||||
|
def run(self, images, filename_prefix="ComfyDeploy_EXR", output_id="output_exr"):
|
||||||
|
if not OPENCV_AVAILABLE:
|
||||||
|
raise ImportError("OpenCV is required to save EXR files. Please ensure opencv-python-headless is in requirements.txt.")
|
||||||
|
|
||||||
|
full_output_folder, filename, counter, subfolder, filename_prefix = (
|
||||||
|
folder_paths.get_save_image_path(
|
||||||
|
filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
results = list()
|
||||||
|
|
||||||
|
for image in images:
|
||||||
|
image_np = image.cpu().numpy()
|
||||||
|
|
||||||
|
if image_np.dtype != np.float32:
|
||||||
|
image_np = image_np.astype(np.float32)
|
||||||
|
|
||||||
|
file = f"{filename}_{counter:05}.exr"
|
||||||
|
file_path = os.path.join(full_output_folder, file)
|
||||||
|
|
||||||
|
image_np_bgr = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)
|
||||||
|
cv2.imwrite(file_path, image_np_bgr)
|
||||||
|
|
||||||
|
results.append({
|
||||||
|
"filename": file,
|
||||||
|
"subfolder": subfolder,
|
||||||
|
"type": self.type,
|
||||||
|
"output_id": output_id, # ADDED
|
||||||
|
})
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
return {"ui": {"images": results}}
|
||||||
|
|
||||||
|
# ALIGNED: Mappings are defined at the bottom of the node file in this project
|
||||||
|
NODE_CLASS_MAPPINGS = {"ComfyDeployOutputEXR": ComfyDeployOutputEXR}
|
||||||
|
NODE_DISPLAY_NAME_MAPPINGS = {"ComfyDeployOutputEXR": "EXR Output (ComfyDeploy)"}
|
||||||
+478
-79
@@ -31,6 +31,7 @@ import torch
|
|||||||
import psutil
|
import psutil
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import io
|
import io
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
# Global session
|
# Global session
|
||||||
client_session = None
|
client_session = None
|
||||||
@@ -264,7 +265,7 @@ def clear_current_prompt(sid):
|
|||||||
streaming_prompt_metadata[sid].running_prompt_ids.clear()
|
streaming_prompt_metadata[sid].running_prompt_ids.clear()
|
||||||
|
|
||||||
|
|
||||||
def post_prompt(json_data):
|
async def post_prompt(json_data):
|
||||||
prompt_server = server.PromptServer.instance
|
prompt_server = server.PromptServer.instance
|
||||||
json_data = prompt_server.trigger_on_prompt(json_data)
|
json_data = prompt_server.trigger_on_prompt(json_data)
|
||||||
|
|
||||||
@@ -280,7 +281,48 @@ def post_prompt(json_data):
|
|||||||
|
|
||||||
if "prompt" in json_data:
|
if "prompt" in json_data:
|
||||||
prompt = json_data["prompt"]
|
prompt = json_data["prompt"]
|
||||||
valid = execution.validate_prompt(prompt)
|
prompt_id = json_data.get("prompt_id") or str(uuid.uuid4())
|
||||||
|
|
||||||
|
partial_execution_targets = None
|
||||||
|
if "partial_execution_targets" in json_data:
|
||||||
|
partial_execution_targets = json_data["partial_execution_targets"]
|
||||||
|
|
||||||
|
# Handle different validate_prompt signatures (newest to oldest)
|
||||||
|
valid = None
|
||||||
|
last_error = None
|
||||||
|
|
||||||
|
# v0.3.48 (3 args)
|
||||||
|
try:
|
||||||
|
valid = await execution.validate_prompt(
|
||||||
|
prompt_id, prompt, partial_execution_targets
|
||||||
|
)
|
||||||
|
except TypeError as e:
|
||||||
|
last_error = e
|
||||||
|
logger.debug(
|
||||||
|
f"validate_prompt with 3 params not supported, trying with 2. Debug: {last_error}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# v0.3.45 - 0.3.47 (2 args)
|
||||||
|
if valid is None:
|
||||||
|
try:
|
||||||
|
valid = await execution.validate_prompt(prompt_id, prompt)
|
||||||
|
except TypeError as e:
|
||||||
|
last_error = e
|
||||||
|
logger.debug(
|
||||||
|
f"validate_prompt with 2 params not supported, trying legacy signature. Debug: {last_error}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# v0.3.44 or older (1 arg)
|
||||||
|
if valid is None:
|
||||||
|
try:
|
||||||
|
valid = execution.validate_prompt(prompt)
|
||||||
|
except TypeError as e:
|
||||||
|
last_error = e
|
||||||
|
logger.error(
|
||||||
|
f"validate_prompt failed with all signatures. Last error: {last_error}"
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
extra_data = {}
|
extra_data = {}
|
||||||
if "extra_data" in json_data:
|
if "extra_data" in json_data:
|
||||||
extra_data = json_data["extra_data"]
|
extra_data = json_data["extra_data"]
|
||||||
@@ -291,8 +333,6 @@ def post_prompt(json_data):
|
|||||||
if "client_id" in json_data:
|
if "client_id" in json_data:
|
||||||
extra_data["client_id"] = json_data["client_id"]
|
extra_data["client_id"] = json_data["client_id"]
|
||||||
if valid[0]:
|
if valid[0]:
|
||||||
# if the prompt id is provided
|
|
||||||
prompt_id = json_data.get("prompt_id") or str(uuid.uuid4())
|
|
||||||
outputs_to_execute = valid[2]
|
outputs_to_execute = valid[2]
|
||||||
prompt_server.prompt_queue.put(
|
prompt_server.prompt_queue.put(
|
||||||
(number, prompt_id, prompt, extra_data, outputs_to_execute)
|
(number, prompt_id, prompt, extra_data, outputs_to_execute)
|
||||||
@@ -499,15 +539,15 @@ def send_prompt(sid: str, inputs: StreamingPrompt):
|
|||||||
|
|
||||||
prompt_id = str(uuid.uuid4())
|
prompt_id = str(uuid.uuid4())
|
||||||
|
|
||||||
prompt = {
|
# prompt = {
|
||||||
"prompt": workflow_api,
|
# "prompt": workflow_api,
|
||||||
"client_id": sid, # "comfy_deploy_instance", #api.client_id
|
# "client_id": sid, # "comfy_deploy_instance", #api.client_id
|
||||||
"prompt_id": prompt_id,
|
# "prompt_id": prompt_id,
|
||||||
"extra_data": {"extra_pnginfo": {"workflow": workflow}},
|
# "extra_data": {"extra_pnginfo": {"workflow": workflow}},
|
||||||
}
|
# }
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = post_prompt(prompt)
|
# res = post_prompt(prompt)
|
||||||
inputs.running_prompt_ids.add(prompt_id)
|
inputs.running_prompt_ids.add(prompt_id)
|
||||||
prompt_metadata[prompt_id] = SimplePrompt(
|
prompt_metadata[prompt_id] = SimplePrompt(
|
||||||
status_endpoint=inputs.status_endpoint,
|
status_endpoint=inputs.status_endpoint,
|
||||||
@@ -518,7 +558,7 @@ def send_prompt(sid: str, inputs: StreamingPrompt):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_type = type(e).__name__
|
error_type = type(e).__name__
|
||||||
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
||||||
stack_trace = traceback.format_exc().strip()
|
# stack_trace = traceback.format_exc().strip()
|
||||||
logger.info(f"error: {error_type}, {e}")
|
logger.info(f"error: {error_type}, {e}")
|
||||||
logger.info(f"stack trace: {stack_trace_short}")
|
logger.info(f"stack trace: {stack_trace_short}")
|
||||||
|
|
||||||
@@ -594,7 +634,7 @@ async def comfy_deploy_run(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = post_prompt(prompt)
|
res = await post_prompt(prompt)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_type = type(e).__name__
|
error_type = type(e).__name__
|
||||||
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
||||||
@@ -663,7 +703,7 @@ async def stream_prompt(data, token):
|
|||||||
# log('info', "Begin prompt", prompt=prompt)
|
# log('info', "Begin prompt", prompt=prompt)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = post_prompt(prompt)
|
res = await post_prompt(prompt)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_type = type(e).__name__
|
error_type = type(e).__name__
|
||||||
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
stack_trace_short = traceback.format_exc().strip().split("\n")[-2]
|
||||||
@@ -1265,22 +1305,11 @@ def handle_execute(class_type, last_node_id, prompt_id, server, unique_id):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
origin_execute = execution.execute
|
origin_execute = execution.execute
|
||||||
|
is_async = asyncio.iscoroutinefunction(origin_execute)
|
||||||
|
|
||||||
def swizzle_execute(
|
if is_async:
|
||||||
server,
|
|
||||||
dynprompt,
|
async def swizzle_execute(
|
||||||
caches,
|
|
||||||
current_item,
|
|
||||||
extra_data,
|
|
||||||
executed,
|
|
||||||
prompt_id,
|
|
||||||
execution_list,
|
|
||||||
pending_subgraph_results,
|
|
||||||
):
|
|
||||||
unique_id = current_item
|
|
||||||
class_type = dynprompt.get_node(unique_id)["class_type"]
|
|
||||||
last_node_id = server.last_node_id
|
|
||||||
result = origin_execute(
|
|
||||||
server,
|
server,
|
||||||
dynprompt,
|
dynprompt,
|
||||||
caches,
|
caches,
|
||||||
@@ -1290,12 +1319,61 @@ try:
|
|||||||
prompt_id,
|
prompt_id,
|
||||||
execution_list,
|
execution_list,
|
||||||
pending_subgraph_results,
|
pending_subgraph_results,
|
||||||
)
|
pending_async_nodes,
|
||||||
handle_execute(class_type, last_node_id, prompt_id, server, unique_id)
|
):
|
||||||
return result
|
unique_id = current_item
|
||||||
|
class_type = dynprompt.get_node(unique_id)["class_type"]
|
||||||
|
last_node_id = server.last_node_id
|
||||||
|
|
||||||
|
result = await origin_execute(
|
||||||
|
server,
|
||||||
|
dynprompt,
|
||||||
|
caches,
|
||||||
|
current_item,
|
||||||
|
extra_data,
|
||||||
|
executed,
|
||||||
|
prompt_id,
|
||||||
|
execution_list,
|
||||||
|
pending_subgraph_results,
|
||||||
|
pending_async_nodes,
|
||||||
|
)
|
||||||
|
|
||||||
|
handle_execute(class_type, last_node_id, prompt_id, server, unique_id)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
|
||||||
|
def swizzle_execute(
|
||||||
|
server,
|
||||||
|
dynprompt,
|
||||||
|
caches,
|
||||||
|
current_item,
|
||||||
|
extra_data,
|
||||||
|
executed,
|
||||||
|
prompt_id,
|
||||||
|
execution_list,
|
||||||
|
pending_subgraph_results,
|
||||||
|
):
|
||||||
|
unique_id = current_item
|
||||||
|
class_type = dynprompt.get_node(unique_id)["class_type"]
|
||||||
|
last_node_id = server.last_node_id
|
||||||
|
|
||||||
|
result = origin_execute(
|
||||||
|
server,
|
||||||
|
dynprompt,
|
||||||
|
caches,
|
||||||
|
current_item,
|
||||||
|
extra_data,
|
||||||
|
executed,
|
||||||
|
prompt_id,
|
||||||
|
execution_list,
|
||||||
|
pending_subgraph_results,
|
||||||
|
)
|
||||||
|
|
||||||
|
handle_execute(class_type, last_node_id, prompt_id, server, unique_id)
|
||||||
|
return result
|
||||||
|
|
||||||
execution.execute = swizzle_execute
|
execution.execute = swizzle_execute
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -1439,10 +1517,6 @@ async def send_json_override(self, event, data, sid=None):
|
|||||||
logger.info(format_table(headers, table_data))
|
logger.info(format_table(headers, table_data))
|
||||||
# print("========================\n")
|
# print("========================\n")
|
||||||
|
|
||||||
timeline = format_execution_timeline(NODE_EXECUTION_TIMES)
|
|
||||||
logger.info(f"\nNode Execution Timeline:\n{timeline}")
|
|
||||||
# Clear the execution times for the next run
|
|
||||||
|
|
||||||
# the last executing event is none, then the workflow is finished
|
# the last executing event is none, then the workflow is finished
|
||||||
if event == "executing" and data.get("node") is None:
|
if event == "executing" and data.get("node") is None:
|
||||||
mark_prompt_done(prompt_id=prompt_id)
|
mark_prompt_done(prompt_id=prompt_id)
|
||||||
@@ -2058,6 +2132,7 @@ async def upload_in_background(
|
|||||||
("model_file", "format", "application/octet-stream"),
|
("model_file", "format", "application/octet-stream"),
|
||||||
("result", "format", "application/octet-stream"),
|
("result", "format", "application/octet-stream"),
|
||||||
("text_file", "format", "text/plain"),
|
("text_file", "format", "text/plain"),
|
||||||
|
("audio", "format", "audio/mpeg"),
|
||||||
]:
|
]:
|
||||||
items = data.get(file_type, [])
|
items = data.get(file_type, [])
|
||||||
|
|
||||||
@@ -2145,6 +2220,7 @@ async def update_run_with_output(
|
|||||||
or "model_file" in data
|
or "model_file" in data
|
||||||
or "result" in data
|
or "result" in data
|
||||||
or "text_file" in data
|
or "text_file" in data
|
||||||
|
or "audio" in data
|
||||||
)
|
)
|
||||||
if bypass_upload and have_upload_media:
|
if bypass_upload and have_upload_media:
|
||||||
print(
|
print(
|
||||||
@@ -2753,51 +2829,57 @@ class UploadQueue:
|
|||||||
logger.error(f"Upload failed: {str(e)}")
|
logger.error(f"Upload failed: {str(e)}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
finally:
|
finally:
|
||||||
# Remove this upload from tracking
|
async with self.lock: # Acquire lock to protect shared dict access
|
||||||
if prompt_id in self.pending_uploads:
|
if prompt_id in self.pending_uploads:
|
||||||
self.pending_uploads[prompt_id].discard(upload_id)
|
self.pending_uploads[prompt_id].discard(upload_id)
|
||||||
# Remove from node tracking if applicable
|
|
||||||
if (
|
|
||||||
node_id
|
|
||||||
and prompt_id in self.node_uploads
|
|
||||||
and node_id in self.node_uploads[prompt_id]
|
|
||||||
):
|
|
||||||
self.node_uploads[prompt_id][node_id].discard(upload_id)
|
|
||||||
|
|
||||||
# If this was the last upload for this node, clean up node data
|
if (
|
||||||
if not self.node_uploads[prompt_id][node_id]:
|
node_id
|
||||||
del self.node_uploads[prompt_id][node_id]
|
and prompt_id in self.node_uploads
|
||||||
if self.node_output_data[prompt_id][node_id]["data"]:
|
and node_id in self.node_uploads[prompt_id]
|
||||||
# Send final node data to API before cleanup
|
):
|
||||||
if prompt_metadata[prompt_id].status_endpoint:
|
self.node_uploads[prompt_id][node_id].discard(upload_id)
|
||||||
body = {
|
|
||||||
"run_id": prompt_id,
|
|
||||||
"output_data": self.node_output_data[
|
|
||||||
prompt_id
|
|
||||||
][node_id]["data"],
|
|
||||||
"node_meta": {"node_id": node_id},
|
|
||||||
}
|
|
||||||
try:
|
|
||||||
await async_request_with_retry(
|
|
||||||
"POST",
|
|
||||||
prompt_metadata[
|
|
||||||
prompt_id
|
|
||||||
].status_endpoint,
|
|
||||||
token=prompt_metadata[prompt_id].token,
|
|
||||||
json=body,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
f"Failed to send final node data: {str(e)}"
|
|
||||||
)
|
|
||||||
del self.node_output_data[prompt_id][node_id]
|
|
||||||
|
|
||||||
# Send status update
|
if not self.node_uploads[prompt_id][node_id]:
|
||||||
await self.update_queue_status(prompt_id)
|
del self.node_uploads[prompt_id][node_id]
|
||||||
|
|
||||||
|
if (
|
||||||
|
prompt_id in self.node_output_data
|
||||||
|
and node_id in self.node_output_data[prompt_id]
|
||||||
|
):
|
||||||
|
node_data = self.node_output_data[prompt_id][
|
||||||
|
node_id
|
||||||
|
]
|
||||||
|
if node_data["data"]:
|
||||||
|
body = {
|
||||||
|
"run_id": prompt_id,
|
||||||
|
"output_data": node_data["data"],
|
||||||
|
"node_meta": {"node_id": node_id},
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
await async_request_with_retry(
|
||||||
|
"POST",
|
||||||
|
prompt_metadata[
|
||||||
|
prompt_id
|
||||||
|
].status_endpoint,
|
||||||
|
token=prompt_metadata[
|
||||||
|
prompt_id
|
||||||
|
].token,
|
||||||
|
json=body,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Failed to send final node data: {str(e)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Safe to delete now (re-check not strictly needed with lock, but harmless)
|
||||||
|
del self.node_output_data[prompt_id][node_id]
|
||||||
|
|
||||||
# If no more pending uploads for this prompt and it's done, update status
|
# If no more pending uploads for this prompt and it's done, update status
|
||||||
if not self.pending_uploads[prompt_id] and is_prompt_done(
|
if (
|
||||||
prompt_id
|
prompt_id in self.pending_uploads
|
||||||
|
and not self.pending_uploads[prompt_id]
|
||||||
|
and is_prompt_done(prompt_id)
|
||||||
):
|
):
|
||||||
# Clean up all data for this prompt
|
# Clean up all data for this prompt
|
||||||
if prompt_id in self.node_uploads:
|
if prompt_id in self.node_uploads:
|
||||||
@@ -2810,9 +2892,12 @@ class UploadQueue:
|
|||||||
loop.create_task(update_run(prompt_id, Status.SUCCESS))
|
loop.create_task(update_run(prompt_id, Status.SUCCESS))
|
||||||
loop.create_task(send("success", {"prompt_id": prompt_id}))
|
loop.create_task(send("success", {"prompt_id": prompt_id}))
|
||||||
|
|
||||||
# Mark task as done
|
# Mark task as done (outside lock to avoid holding it unnecessarily)
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
|
# Send status update (also outside lock)
|
||||||
|
await self.update_queue_status(prompt_id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in upload worker: {str(e)}")
|
logger.error(f"Error in upload worker: {str(e)}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
@@ -2883,3 +2968,317 @@ def format_execution_timeline(execution_times):
|
|||||||
current_time += duration
|
current_time += duration
|
||||||
|
|
||||||
return format_table(headers, rows)
|
return format_table(headers, rows)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui-deploy/auth-response")
|
||||||
|
async def auth_response_proxy(request):
|
||||||
|
request_id = request.rel_url.query.get("request_id")
|
||||||
|
api_url = request.rel_url.query.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
|
||||||
|
if not request_id:
|
||||||
|
return web.json_response({"error": "request_id is required"}, status=400)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/platform/comfyui/auth-response?request_id={request_id}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.get(target_url) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/workflow")
|
||||||
|
async def create_workflow_proxy(request):
|
||||||
|
data = await request.json()
|
||||||
|
name = data.get("name")
|
||||||
|
workflow_json = data.get("workflow_json")
|
||||||
|
workflow_api = data.get("workflow_api")
|
||||||
|
machine_id = data.get("machine_id")
|
||||||
|
api_url = data.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
if not name or not workflow_json or not workflow_api:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "name, workflow_json, workflow_api are required"}, status=400
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/workflow"
|
||||||
|
|
||||||
|
request_body = {
|
||||||
|
"name": name,
|
||||||
|
"workflow_json": json.dumps(workflow_json),
|
||||||
|
"workflow_api": json.dumps(workflow_api),
|
||||||
|
"machine_id": machine_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.post(
|
||||||
|
target_url,
|
||||||
|
json=request_body,
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": auth_header,
|
||||||
|
},
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/workflow/version")
|
||||||
|
async def create_workflow_version_proxy(request):
|
||||||
|
data = await request.json()
|
||||||
|
workflow_id = data.get("workflow_id")
|
||||||
|
workflow = data.get("workflow")
|
||||||
|
workflow_api = data.get("workflow_api")
|
||||||
|
comment = data.get("comment", "")
|
||||||
|
api_url = data.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/workflow/{workflow_id}/version"
|
||||||
|
|
||||||
|
request_body = {
|
||||||
|
"workflow": workflow,
|
||||||
|
"workflow_api": workflow_api,
|
||||||
|
"comment": comment,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.post(
|
||||||
|
target_url,
|
||||||
|
json=request_body,
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": auth_header,
|
||||||
|
},
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui-deploy/workflows")
|
||||||
|
async def get_workflows_proxy(request):
|
||||||
|
api_url = request.rel_url.query.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
search = request.rel_url.query.get("search", "")
|
||||||
|
limit = request.rel_url.query.get("limit", 10)
|
||||||
|
offset = request.rel_url.query.get("offset", 0)
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build query parameters properly
|
||||||
|
params = {}
|
||||||
|
if search:
|
||||||
|
params["search"] = search
|
||||||
|
if limit:
|
||||||
|
params["limit"] = limit
|
||||||
|
if offset:
|
||||||
|
params["offset"] = offset
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/workflows"
|
||||||
|
if params:
|
||||||
|
target_url += f"?{urlencode(params)}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.get(
|
||||||
|
target_url,
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": auth_header,
|
||||||
|
},
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
# for getting a workflow by id
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui-deploy/workflow")
|
||||||
|
async def get_workflow_proxy(request):
|
||||||
|
workflow_id = request.rel_url.query.get("workflow_id")
|
||||||
|
api_url = request.rel_url.query.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/workflow/{workflow_id}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.get(
|
||||||
|
target_url, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
# for getting a machine by id
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui-deploy/machine")
|
||||||
|
async def get_machine_proxy(request):
|
||||||
|
machine_id = request.rel_url.query.get("machine_id")
|
||||||
|
api_url = request.rel_url.query.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/machine/{machine_id}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.get(
|
||||||
|
target_url, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
# for fetching docker steps from current snapshot
|
||||||
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/snapshot-to-docker")
|
||||||
|
async def snapshot_to_docker_proxy(request):
|
||||||
|
data = await request.json()
|
||||||
|
snapshot = data.get("snapshot")
|
||||||
|
api_url = data.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/snapshot-to-docker"
|
||||||
|
|
||||||
|
request_body = snapshot
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.post(
|
||||||
|
target_url, json=request_body, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
# update a serverless machine with machine id
|
||||||
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/machine/update")
|
||||||
|
async def update_machine_proxy(request):
|
||||||
|
data = await request.json()
|
||||||
|
machine_id = data.get("machine_id")
|
||||||
|
comfyui_version = data.get("comfyui_version", None)
|
||||||
|
docker_steps = data.get("docker_steps")
|
||||||
|
api_url = data.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/machine/serverless/{machine_id}"
|
||||||
|
|
||||||
|
request_body = {"docker_command_steps": docker_steps}
|
||||||
|
|
||||||
|
if comfyui_version:
|
||||||
|
request_body["comfyui_version"] = comfyui_version
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.patch(
|
||||||
|
target_url, json=request_body, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.post("/comfyui-deploy/machine/create")
|
||||||
|
async def create_machine_proxy(request):
|
||||||
|
data = await request.json()
|
||||||
|
name = data.get("name")
|
||||||
|
docker_command_steps = data.get("docker_command_steps")
|
||||||
|
comfyui_version = data.get("comfyui_version")
|
||||||
|
api_url = data.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/machine/serverless"
|
||||||
|
|
||||||
|
request_body = {
|
||||||
|
"name": name,
|
||||||
|
"docker_command_steps": docker_command_steps,
|
||||||
|
"comfyui_version": comfyui_version,
|
||||||
|
"gpu": "A10G",
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.post(
|
||||||
|
target_url, json=request_body, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
# get latest comfyui version
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui-deploy/comfyui-version")
|
||||||
|
async def get_comfyui_version_proxy(request):
|
||||||
|
api_url = request.rel_url.query.get("api_url", "https://api.comfydeploy.com")
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return web.json_response(
|
||||||
|
{"error": "Authorization header is required"}, status=401
|
||||||
|
)
|
||||||
|
|
||||||
|
target_url = f"{api_url}/api/latest-hashes"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await ensure_client_session()
|
||||||
|
async with client_session.get(
|
||||||
|
target_url, headers={"Authorization": auth_header}
|
||||||
|
) as response:
|
||||||
|
json_data = await response.json()
|
||||||
|
return web.json_response(json_data, status=response.status)
|
||||||
|
except Exception as e:
|
||||||
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "comfyui-deploy"
|
name = "comfyui-deploy"
|
||||||
description = "Open source comfyui deployment platform, a vercel for generative workflow infra."
|
description = "Open source comfyui deployment platform, a vercel for generative workflow infra."
|
||||||
version = "2.1.0"
|
version = "2.3.2"
|
||||||
license = { file = "LICENSE" }
|
license = { file = "LICENSE" }
|
||||||
dependencies = ["aiofiles", "pydantic", "opencv-python", "imageio-ffmpeg", "tabulate", "brotli"]
|
dependencies = ["aiofiles", "pydantic", "opencv-python", "imageio-ffmpeg", "tabulate", "brotli"]
|
||||||
|
|
||||||
|
|||||||
+1166
-506
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
|||||||
|
// Snapshot Utilities
|
||||||
|
// Centralized snapshot fetching with ComfyUI version fallback
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the current snapshot with ComfyUI version fallback
|
||||||
|
* If the snapshot response has null comfyui field, it will fetch the latest ComfyUI version
|
||||||
|
* and update the snapshot with the comfyui_hash
|
||||||
|
*
|
||||||
|
* @param {Function} getDataFn - Function that returns { apiKey, apiUrl } for ComfyUI version API calls
|
||||||
|
* @returns {Promise<Object>} - The snapshot data with comfyui field populated
|
||||||
|
*/
|
||||||
|
export async function fetchSnapshot(getDataFn = null) {
|
||||||
|
try {
|
||||||
|
// Fetch the current snapshot
|
||||||
|
const response = await fetch("/snapshot/get_current");
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Snapshot fetch failed: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const snapshot = await response.json();
|
||||||
|
|
||||||
|
// Check if comfyui field is null and we have getDataFn for fallback
|
||||||
|
if (snapshot.comfyui === null && getDataFn) {
|
||||||
|
console.log(
|
||||||
|
"ComfyUI version is null in snapshot, fetching latest version..."
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = getDataFn();
|
||||||
|
if (data && data.apiKey) {
|
||||||
|
const comfyuiVersionResponse = await fetch(
|
||||||
|
`/comfyui-deploy/comfyui-version?api_url=${encodeURIComponent(
|
||||||
|
data.apiUrl || "https://api.comfydeploy.com"
|
||||||
|
)}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${data.apiKey}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (comfyuiVersionResponse.ok) {
|
||||||
|
const versionData = await comfyuiVersionResponse.json();
|
||||||
|
if (versionData.comfyui_hash) {
|
||||||
|
console.log(
|
||||||
|
`Using ComfyUI hash from API: ${versionData.comfyui_hash}`
|
||||||
|
);
|
||||||
|
snapshot.comfyui = versionData.comfyui_hash;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
"Failed to fetch ComfyUI version from API:",
|
||||||
|
comfyuiVersionResponse.status
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Error fetching ComfyUI version fallback:", error);
|
||||||
|
// Continue with original snapshot even if fallback fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshot;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching snapshot:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple snapshot fetch without ComfyUI version fallback
|
||||||
|
* Use this when you don't need the ComfyUI version fallback logic
|
||||||
|
*
|
||||||
|
* @returns {Promise<Object>} - The snapshot data as-is
|
||||||
|
*/
|
||||||
|
export async function fetchSnapshotSimple() {
|
||||||
|
const response = await fetch("/snapshot/get_current");
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Snapshot fetch failed: ${response.status}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
@@ -0,0 +1,417 @@
|
|||||||
|
// Workflow list management
|
||||||
|
let workflowsState = {
|
||||||
|
workflows: [],
|
||||||
|
offset: 0,
|
||||||
|
limit: 20,
|
||||||
|
loading: false,
|
||||||
|
hasMore: true,
|
||||||
|
initialized: false,
|
||||||
|
currentSearch: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make workflowsState accessible globally
|
||||||
|
window.workflowsState = workflowsState;
|
||||||
|
|
||||||
|
async function fetchWorkflows(getData, offset = 0, limit = 20, search = "") {
|
||||||
|
try {
|
||||||
|
const data = getData();
|
||||||
|
if (!data.apiKey) {
|
||||||
|
throw new Error("API key not configured");
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
offset: offset.toString(),
|
||||||
|
limit: limit.toString(),
|
||||||
|
api_url: data.apiUrl || "https://api.comfydeploy.com",
|
||||||
|
...(search && { search }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await fetch(`/comfyui-deploy/workflows?${params}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${data.apiKey}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch workflows: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log("result", result);
|
||||||
|
return Array.isArray(result) ? result : [];
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching workflows:", error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createWorkflowItem(workflow, getTimeAgo, getData) {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
let loadingToast = null;
|
||||||
|
li.style.cssText = `
|
||||||
|
border-bottom: 1px solid #444;
|
||||||
|
background: transparent;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
cursor: pointer;
|
||||||
|
`;
|
||||||
|
|
||||||
|
li.addEventListener("mouseenter", () => {
|
||||||
|
li.style.background = "#333";
|
||||||
|
});
|
||||||
|
|
||||||
|
li.addEventListener("mouseleave", () => {
|
||||||
|
li.style.background = "transparent";
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add click handler to fetch and load workflow data
|
||||||
|
li.addEventListener("click", async () => {
|
||||||
|
try {
|
||||||
|
const data = getData();
|
||||||
|
if (!data.apiKey) {
|
||||||
|
console.error("No API key configured");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show loading toast
|
||||||
|
loadingToast = window.app.extensionManager.toast.add({
|
||||||
|
severity: "info",
|
||||||
|
summary: "Loading workflow...",
|
||||||
|
detail: `Loading "${workflow.name}"`,
|
||||||
|
life: 3000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
workflow_id: workflow.id,
|
||||||
|
api_url: data.apiUrl || "https://api.comfydeploy.com",
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await fetch(`/comfyui-deploy/workflow?${params}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${data.apiKey}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch workflow: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflowData = await response.json();
|
||||||
|
console.log("Workflow data:", workflowData);
|
||||||
|
|
||||||
|
// Load the workflow into the graph
|
||||||
|
if (workflowData.versions && workflowData.versions.length > 0) {
|
||||||
|
const latestVersion = workflowData.versions[0];
|
||||||
|
if (latestVersion.workflow && window.app) {
|
||||||
|
// Load the workflow
|
||||||
|
window.app.loadGraphData(latestVersion.workflow);
|
||||||
|
|
||||||
|
// Wait a bit for the graph to fully load before checking for ComfyDeploy node
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
|
|
||||||
|
// Check if ComfyDeploy node exists, if not add it back
|
||||||
|
const graph = window.app.graph;
|
||||||
|
let deployMeta = graph.findNodesByType("ComfyDeploy");
|
||||||
|
|
||||||
|
if (deployMeta.length === 0) {
|
||||||
|
// Add ComfyDeploy node with workflow metadata
|
||||||
|
graph.beforeChange();
|
||||||
|
const node = LiteGraph.createNode("ComfyDeploy");
|
||||||
|
node.configure({
|
||||||
|
widgets_values: [
|
||||||
|
workflow.name, // workflow_name
|
||||||
|
workflow.id, // workflow_id
|
||||||
|
latestVersion.version, // version
|
||||||
|
],
|
||||||
|
});
|
||||||
|
node.pos = [0, 0];
|
||||||
|
graph.add(node);
|
||||||
|
graph.afterChange();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Added ComfyDeploy node with: name="${workflow.name}", id="${workflow.id}", version="${latestVersion.version}"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show success toast
|
||||||
|
window.app.extensionManager.toast.add({
|
||||||
|
severity: "success",
|
||||||
|
summary: "Workflow loaded successfully",
|
||||||
|
detail: `Loaded "${workflow.name}" v${latestVersion.version}`,
|
||||||
|
life: 3000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading workflow:", error);
|
||||||
|
// Show error toast
|
||||||
|
window.app.extensionManager.toast.add({
|
||||||
|
severity: "error",
|
||||||
|
summary: "Failed to load workflow",
|
||||||
|
detail: error.message,
|
||||||
|
life: 5000,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (loadingToast) {
|
||||||
|
loadingToast.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedDate = new Date(workflow.updated_at);
|
||||||
|
const timeAgo = getTimeAgo(updatedDate);
|
||||||
|
|
||||||
|
li.innerHTML = `
|
||||||
|
<div style="padding: 12px 16px;">
|
||||||
|
<div style="display: flex; align-items: flex-start; gap: 12px;">
|
||||||
|
${
|
||||||
|
workflow.cover_image
|
||||||
|
? `<img src="${workflow.cover_image}"
|
||||||
|
style="width: 40px; height: 40px; border-radius: 4px; object-fit: cover; flex-shrink: 0;"
|
||||||
|
onerror="this.style.display='none'">`
|
||||||
|
: `<div style="width: 40px; height: 40px; border-radius: 4px; background: #444; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; color: #888;">
|
||||||
|
${workflow.name.charAt(0).toUpperCase()}
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
<div style="flex: 1; min-width: 0;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 4px;">
|
||||||
|
<h4 style="margin: 0; font-size: 14px; font-weight: 400; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
|
||||||
|
${workflow.name}
|
||||||
|
</h4>
|
||||||
|
${
|
||||||
|
workflow.pinned
|
||||||
|
? `<span style="color: #ffd700; font-size: 12px;">📌</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
workflow.description
|
||||||
|
? `<p style="margin: 0 0 8px 0; font-size: 12px; color: #bbb; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">
|
||||||
|
${workflow.description}
|
||||||
|
</p>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px; margin-top: 8px;">
|
||||||
|
<img src="${workflow.user_icon}"
|
||||||
|
style="width: 16px; height: 16px; border-radius: 50%;"
|
||||||
|
onerror="this.style.display='none'">
|
||||||
|
<span style="font-size: 11px; color: #888;">
|
||||||
|
${workflow.user_name} • Updated ${timeAgo}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
return li;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadMoreWorkflows(element, getData, getTimeAgo) {
|
||||||
|
if (workflowsState.loading || !workflowsState.hasMore) return;
|
||||||
|
|
||||||
|
workflowsState.loading = true;
|
||||||
|
|
||||||
|
const workflowsList = element.querySelector("#workflows-list");
|
||||||
|
const workflowsLoading = element.querySelector("#workflows-loading");
|
||||||
|
|
||||||
|
// Show loading indicator
|
||||||
|
workflowsLoading.style.display = "flex";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newWorkflows = await fetchWorkflows(
|
||||||
|
getData,
|
||||||
|
workflowsState.offset,
|
||||||
|
workflowsState.limit,
|
||||||
|
workflowsState.currentSearch
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newWorkflows.length === 0) {
|
||||||
|
workflowsState.hasMore = false;
|
||||||
|
} else {
|
||||||
|
workflowsState.workflows.push(...newWorkflows);
|
||||||
|
workflowsState.offset += newWorkflows.length;
|
||||||
|
|
||||||
|
// Render new workflow items
|
||||||
|
newWorkflows.forEach((workflow) => {
|
||||||
|
const workflowItem = createWorkflowItem(workflow, getTimeAgo, getData);
|
||||||
|
workflowsList.appendChild(workflowItem);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading more workflows:", error);
|
||||||
|
} finally {
|
||||||
|
workflowsState.loading = false;
|
||||||
|
workflowsLoading.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupInfiniteScroll(container, element, getData, getTimeAgo) {
|
||||||
|
let isScrolling = false;
|
||||||
|
|
||||||
|
container.addEventListener("scroll", () => {
|
||||||
|
if (isScrolling) return;
|
||||||
|
|
||||||
|
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||||
|
|
||||||
|
// Load more when scrolled to bottom (with 100px threshold)
|
||||||
|
if (scrollTop + clientHeight >= scrollHeight - 100) {
|
||||||
|
isScrolling = true;
|
||||||
|
loadMoreWorkflows(element, getData, getTimeAgo).finally(() => {
|
||||||
|
isScrolling = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initializeWorkflowsList(element, getData, getTimeAgo) {
|
||||||
|
const workflowsContainer = element.querySelector("#workflows-container");
|
||||||
|
const workflowsList = element.querySelector("#workflows-list");
|
||||||
|
const workflowsLoading = element.querySelector("#workflows-loading");
|
||||||
|
|
||||||
|
// Check if already initialized AND the DOM elements still exist
|
||||||
|
if (
|
||||||
|
workflowsState.initialized &&
|
||||||
|
workflowsList &&
|
||||||
|
workflowsList.children.length > 0
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Reset state (always reset when reinitializing)
|
||||||
|
workflowsState = {
|
||||||
|
workflows: [],
|
||||||
|
offset: 0,
|
||||||
|
limit: 20,
|
||||||
|
loading: false,
|
||||||
|
hasMore: true,
|
||||||
|
initialized: true,
|
||||||
|
currentSearch: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear existing content in case of reinitialization
|
||||||
|
if (workflowsList) {
|
||||||
|
workflowsList.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show container and loading
|
||||||
|
workflowsContainer.style.display = "block";
|
||||||
|
workflowsLoading.style.display = "flex";
|
||||||
|
|
||||||
|
// Style the workflows list for full height scrolling
|
||||||
|
workflowsList.style.cssText = `
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
height: calc(100vh - 550px);
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: #666 transparent;
|
||||||
|
border-top: 1px solid #444;
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Add webkit scrollbar styles
|
||||||
|
const style = document.createElement("style");
|
||||||
|
style.textContent = `
|
||||||
|
#workflows-list::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
#workflows-list::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
#workflows-list::-webkit-scrollbar-thumb {
|
||||||
|
background: #666;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
#workflows-list::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #777;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
document.head.appendChild(style);
|
||||||
|
|
||||||
|
// Setup infinite scroll
|
||||||
|
setupInfiniteScroll(workflowsList, element, getData, getTimeAgo);
|
||||||
|
|
||||||
|
// Load initial workflows
|
||||||
|
await loadMoreWorkflows(element, getData, getTimeAgo);
|
||||||
|
|
||||||
|
// Show the list
|
||||||
|
workflowsList.style.display = "block";
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error initializing workflows list:", error);
|
||||||
|
workflowsLoading.innerHTML = `
|
||||||
|
<div style="text-align: center; color: #e74c3c; font-size: 12px; padding: 20px;">
|
||||||
|
<div>Failed to load workflows</div>
|
||||||
|
<button onclick="initializeWorkflowsList(this.closest('.comfy-menu'), getData, getTimeAgo)"
|
||||||
|
style="margin-top: 8px; padding: 4px 8px; font-size: 11px; background: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; cursor: pointer;">
|
||||||
|
Retry
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search functionality
|
||||||
|
function addWorkflowSearch(element, getData, getTimeAgo) {
|
||||||
|
const workflowsContainer = element.querySelector("#workflows-container");
|
||||||
|
const h4 = workflowsContainer.querySelector("h4");
|
||||||
|
|
||||||
|
const searchContainer = document.createElement("div");
|
||||||
|
searchContainer.style.cssText = "margin-bottom: 12px;";
|
||||||
|
|
||||||
|
const searchInput = document.createElement("input");
|
||||||
|
searchInput.type = "text";
|
||||||
|
searchInput.placeholder = "Search workflows...";
|
||||||
|
searchInput.style.cssText = `
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #555;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: #333;
|
||||||
|
color: #fff;
|
||||||
|
`;
|
||||||
|
|
||||||
|
let searchTimeout;
|
||||||
|
searchInput.addEventListener("input", (e) => {
|
||||||
|
clearTimeout(searchTimeout);
|
||||||
|
searchTimeout = setTimeout(async () => {
|
||||||
|
const searchTerm = e.target.value.trim();
|
||||||
|
|
||||||
|
// Update the tracked search term
|
||||||
|
workflowsState.currentSearch = searchTerm;
|
||||||
|
|
||||||
|
// Reset state for new search
|
||||||
|
workflowsState.workflows = [];
|
||||||
|
workflowsState.offset = 0;
|
||||||
|
workflowsState.hasMore = true;
|
||||||
|
|
||||||
|
// Clear current list
|
||||||
|
const workflowsList = element.querySelector("#workflows-list");
|
||||||
|
workflowsList.innerHTML = "";
|
||||||
|
|
||||||
|
// Load with search term
|
||||||
|
workflowsState.loading = false;
|
||||||
|
await loadMoreWorkflows(element, getData, getTimeAgo);
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
searchContainer.appendChild(searchInput);
|
||||||
|
h4.after(searchContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export the functions
|
||||||
|
export {
|
||||||
|
initializeWorkflowsList,
|
||||||
|
addWorkflowSearch,
|
||||||
|
workflowsState,
|
||||||
|
fetchWorkflows,
|
||||||
|
loadMoreWorkflows,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user