Browse Source

updated comfyworkflows.com share component

pull/300/head
thecooltechguy 11 months ago
parent
commit
4345c3f27f
  1. 58
      __init__.py
  2. 13
      js/comfyui-share-common.js

58
__init__.py

@ -16,6 +16,7 @@ from urllib.parse import urlparse
import http.client import http.client
import re import re
import nodes import nodes
import hashlib
try: try:
import cm_global import cm_global
@ -1930,6 +1931,47 @@ def has_provided_comfyworkflows_auth(comfyworkflows_sharekey):
return comfyworkflows_sharekey.strip() return comfyworkflows_sharekey.strip()
def extract_model_file_names(json_data):
"""Extract unique file names from the input JSON data."""
file_names = set()
model_filename_extensions = {'.safetensors', '.ckpt', '.pt', '.pth', '.bin'}
# Recursively search for file names in the JSON data
def recursive_search(data):
if isinstance(data, dict):
for value in data.values():
recursive_search(value)
elif isinstance(data, list):
for item in data:
recursive_search(item)
elif isinstance(data, str) and '.' in data:
file_names.add(os.path.basename(data)) # file_names.add(data)
recursive_search(json_data)
return [f for f in list(file_names) if os.path.splitext(f)[1] in model_filename_extensions]
def find_file_paths(base_dir, file_names):
"""Find the paths of the files in the base directory."""
file_paths = {}
for root, dirs, files in os.walk(base_dir):
# Exclude certain directories
dirs[:] = [d for d in dirs if d not in ['.git']]
for file in files:
if file in file_names:
file_paths[file] = os.path.join(root, file)
return file_paths
def compute_sha256_checksum(filepath):
"""Compute the SHA256 checksum of a file, in chunks"""
sha256 = hashlib.sha256()
with open(filepath, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b''):
sha256.update(chunk)
return sha256.hexdigest()
@server.PromptServer.instance.routes.post("/manager/share") @server.PromptServer.instance.routes.post("/manager/share")
async def share_art(request): async def share_art(request):
# get json data # get json data
@ -1990,7 +2032,6 @@ async def share_art(request):
"assetFileType": assetFileType, "assetFileType": assetFileType,
"workflowJsonFileName" : 'workflow.json', "workflowJsonFileName" : 'workflow.json',
"workflowJsonFileType" : 'application/json', "workflowJsonFileType" : 'application/json',
}, },
) as resp: ) as resp:
assert resp.status == 200 assert resp.status == 200
@ -2010,6 +2051,17 @@ async def share_art(request):
async with session.put(workflowJsonFilePresignedUrl, data=json.dumps(prompt['workflow']).encode('utf-8')) as resp: async with session.put(workflowJsonFilePresignedUrl, data=json.dumps(prompt['workflow']).encode('utf-8')) as resp:
assert resp.status == 200 assert resp.status == 200
model_filenames = extract_model_file_names(prompt['workflow'])
model_file_paths = find_file_paths(folder_paths.base_path, model_filenames)
models_info = {}
for filename, filepath in model_file_paths.items():
models_info[filename] = {
"filename": filename,
"sha256_checksum": compute_sha256_checksum(filepath),
"relative_path": os.path.relpath(filepath, folder_paths.base_path),
}
# make a POST request to /api/upload_workflow with form data key values # make a POST request to /api/upload_workflow with form data key values
async with aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(verify_ssl=False)) as session: async with aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(verify_ssl=False)) as session:
form = aiohttp.FormData() form = aiohttp.FormData()
@ -2025,7 +2077,9 @@ async def share_art(request):
form.add_field("shareWorkflowTitle", title) form.add_field("shareWorkflowTitle", title)
form.add_field("shareWorkflowDescription", description) form.add_field("shareWorkflowDescription", description)
form.add_field("shareWorkflowIsNSFW", str(is_nsfw).lower()) form.add_field("shareWorkflowIsNSFW", str(is_nsfw).lower())
form.add_field("currentSnapshot", json.dumps(get_current_snapshot()))
form.add_field("modelsInfo", json.dumps(models_info))
async with session.post( async with session.post(
f"{share_endpoint}/upload_workflow", f"{share_endpoint}/upload_workflow",
data=form, data=form,

13
js/comfyui-share-common.js vendored

@ -9,6 +9,7 @@ export const SUPPORTED_OUTPUT_NODE_TYPES = [
"VHS_VideoCombine", "VHS_VideoCombine",
"ADE_AnimateDiffCombine", "ADE_AnimateDiffCombine",
"SaveAnimatedWEBP", "SaveAnimatedWEBP",
"CR Image Output"
] ]
var docStyle = document.createElement('style'); var docStyle = document.createElement('style');
@ -46,7 +47,7 @@ export function getPotentialOutputsAndOutputNodes(nodes) {
continue; continue;
} }
if (node.type === "SaveImage") { if (node.type === "SaveImage" || node.type === "CR Image Output") {
// check if node has an 'images' array property // check if node has an 'images' array property
if (node.hasOwnProperty("images") && Array.isArray(node.images)) { if (node.hasOwnProperty("images") && Array.isArray(node.images)) {
// iterate over the images array and add each image to the potential_outputs array // iterate over the images array and add each image to the potential_outputs array
@ -247,7 +248,7 @@ export class ShareDialogChooser extends ComfyDialog {
key: "comfyworkflows", key: "comfyworkflows",
textContent: "ComfyWorkflows", textContent: "ComfyWorkflows",
website: "https://comfyworkflows.com", website: "https://comfyworkflows.com",
description: "Share ComfyUI art on comfyworkflows.com", description: "Share & browse thousands of ComfyUI workflows and art 🎨<br/><br/><a style='color:white;' href='https://comfyworkflows.com' target='_blank'>ComfyWorkflows.com</a>",
onclick: () => { onclick: () => {
showShareDialog('comfyworkflows').then((suc) => { showShareDialog('comfyworkflows').then((suc) => {
suc && this.close(); suc && this.close();
@ -291,7 +292,7 @@ export class ShareDialogChooser extends ComfyDialog {
}); });
const description = $el("p", { const description = $el("p", {
textContent: b.description, innerHTML: b.description,
style: { style: {
'text-align': 'left', 'text-align': 'left',
color: 'white', color: 'white',
@ -580,7 +581,7 @@ export class ShareDialog extends ComfyDialog {
padding: "5px", padding: "5px",
borderRadius: "5px", borderRadius: "5px",
backgroundColor: "#222" backgroundColor: "#222"
} },
}, [ }, [
$el("summary", { $el("summary", {
style: { style: {
@ -591,7 +592,7 @@ export class ShareDialog extends ComfyDialog {
$el("h4", { $el("h4", {
textContent: "Share key (found on your profile page)", textContent: "Share key (found on your profile page)",
}, []), }, []),
$el("p", { size: 3, color: "white" }, ["When provided, your art will be saved to your account."]), $el("p", { size: 3, color: "white" }, ["If provided, your art will be saved to your account. Otherwise, it will be shared anonymously."]),
this.cw_sharekey_input, this.cw_sharekey_input,
]), ]),
@ -741,7 +742,7 @@ export class ShareDialog extends ComfyDialog {
} }
} }
if (destinations.includes("comfyworkflows") && !this.cw_sharekey_input.value && !confirm("You have NOT set your ComfyWorkflows.com share key. Your art will NOT be connected to your account (it will be shared anonymously). Continue?")) { if (destinations.includes("comfyworkflows") && !this.cw_sharekey_input.value && false) { //!confirm("You have NOT set your ComfyWorkflows.com share key. Your art will NOT be connected to your account (it will be shared anonymously). Continue?")) {
return; return;
} }

Loading…
Cancel
Save