From b6b88dcf5d93505f7345d66c3564c0017543a9bb Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 9 Jun 2026 13:41:57 -0300 Subject: [PATCH] Add Image MetaHub CTA buttons to save nodes --- js/metahub_save_cta.js | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 js/metahub_save_cta.js diff --git a/js/metahub_save_cta.js b/js/metahub_save_cta.js new file mode 100644 index 0000000..5a4a886 --- /dev/null +++ b/js/metahub_save_cta.js @@ -0,0 +1,65 @@ +import { app } from "../../scripts/app.js"; + +const METAHUB_SAVE_NODE_CLASSES = new Set([ + "MetaHubSaveImage", + "MetaHubSaveNode", + "MetaHubSaveVideoNode", +]); + +const IMAGE_METAHUB_URL = "https://www.imagemetahub.com/"; +const IMAGE_METAHUB_DEEPLINK = "imagemetahub://open"; + +function getWidgetValue(node, widgetName) { + const widget = node.widgets?.find((candidate) => candidate.name === widgetName); + const value = widget?.value; + return typeof value === "string" ? value.trim() : ""; +} + +function buildDeepLink(node) { + const outputPath = getWidgetValue(node, "output_path"); + const params = new URLSearchParams({ source: "comfyui-save-node" }); + + if (outputPath) { + params.set("path", outputPath); + } + + return `${IMAGE_METAHUB_DEEPLINK}?${params.toString()}`; +} + +function openUrl(url) { + window.open(url, "_blank", "noopener,noreferrer"); +} + +function addMetaHubCTA(node) { + if (!METAHUB_SAVE_NODE_CLASSES.has(node.comfyClass)) { + return; + } + + if (node.__imageMetaHubCTAAdded) { + return; + } + + node.__imageMetaHubCTAAdded = true; + + node.addWidget( + "button", + "Open in Image MetaHub", + null, + () => openUrl(buildDeepLink(node)) + ); + + node.addWidget( + "button", + "Download Image MetaHub", + null, + () => openUrl(IMAGE_METAHUB_URL) + ); +} + +app.registerExtension({ + name: "ImageMetaHub.SaveNodeCTA", + + async nodeCreated(node) { + addMetaHubCTA(node); + }, +});