From 4345c3f27f8f7a51f99db95c26032cfcfa873ee6 Mon Sep 17 00:00:00 2001 From: thecooltechguy Date: Fri, 5 Jan 2024 19:13:02 -0800 Subject: [PATCH 1/2] updated comfyworkflows.com share component --- __init__.py | 58 ++++++++++++++++++++++++++++++++++++-- js/comfyui-share-common.js | 13 +++++---- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index b4ff868..be53fc5 100644 --- a/__init__.py +++ b/__init__.py @@ -16,6 +16,7 @@ from urllib.parse import urlparse import http.client import re import nodes +import hashlib try: import cm_global @@ -1930,6 +1931,47 @@ def has_provided_comfyworkflows_auth(comfyworkflows_sharekey): 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") async def share_art(request): # get json data @@ -1990,7 +2032,6 @@ async def share_art(request): "assetFileType": assetFileType, "workflowJsonFileName" : 'workflow.json', "workflowJsonFileType" : 'application/json', - }, ) as resp: 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: 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 async with aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(verify_ssl=False)) as session: form = aiohttp.FormData() @@ -2025,7 +2077,9 @@ async def share_art(request): form.add_field("shareWorkflowTitle", title) form.add_field("shareWorkflowDescription", description) 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( f"{share_endpoint}/upload_workflow", data=form, diff --git a/js/comfyui-share-common.js b/js/comfyui-share-common.js index 9875f0c..d85637e 100644 --- a/js/comfyui-share-common.js +++ b/js/comfyui-share-common.js @@ -9,6 +9,7 @@ export const SUPPORTED_OUTPUT_NODE_TYPES = [ "VHS_VideoCombine", "ADE_AnimateDiffCombine", "SaveAnimatedWEBP", + "CR Image Output" ] var docStyle = document.createElement('style'); @@ -46,7 +47,7 @@ export function getPotentialOutputsAndOutputNodes(nodes) { continue; } - if (node.type === "SaveImage") { + if (node.type === "SaveImage" || node.type === "CR Image Output") { // check if node has an 'images' array property if (node.hasOwnProperty("images") && Array.isArray(node.images)) { // 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", textContent: "ComfyWorkflows", website: "https://comfyworkflows.com", - description: "Share ComfyUI art on comfyworkflows.com", + description: "Share & browse thousands of ComfyUI workflows and art 🎨

ComfyWorkflows.com", onclick: () => { showShareDialog('comfyworkflows').then((suc) => { suc && this.close(); @@ -291,7 +292,7 @@ export class ShareDialogChooser extends ComfyDialog { }); const description = $el("p", { - textContent: b.description, + innerHTML: b.description, style: { 'text-align': 'left', color: 'white', @@ -580,7 +581,7 @@ export class ShareDialog extends ComfyDialog { padding: "5px", borderRadius: "5px", backgroundColor: "#222" - } + }, }, [ $el("summary", { style: { @@ -591,7 +592,7 @@ export class ShareDialog extends ComfyDialog { $el("h4", { 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, ]), @@ -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; } From f09bb72e67db99e58ad4345ec5892692fc24e834 Mon Sep 17 00:00:00 2001 From: thecooltechguy Date: Fri, 5 Jan 2024 21:26:11 -0800 Subject: [PATCH 2/2] fixed share output option not showing in context menu --- js/comfyui-manager.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index aa4c4e4..fd1f2d3 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -563,13 +563,7 @@ function newDOMTokenList(initialTokens) { * Check whether the node is a potential output node (img, gif or video output) */ const isOutputNode = (node) => { - return [ - "VHS_VideoCombine", - "PreviewImage", - "SaveImage", - "ADE_AnimateDiffCombine", - "SaveAnimatedWEBP", - ].includes(node.type); + return SUPPORTED_OUTPUT_NODE_TYPES.includes(node.type); } // -----------