From 5266c2bb14b9d8ff4056948595c58d2f4a5df75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=AA=E5=B3=B0?= Date: Thu, 8 Aug 2024 17:57:02 +0800 Subject: [PATCH] Extend SDBaseVerNumber node --- easyapi/UtilNode.py | 2 +- static/js/workflows.js | 108 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/easyapi/UtilNode.py b/easyapi/UtilNode.py index 2e68ed2..b03e236 100644 --- a/easyapi/UtilNode.py +++ b/easyapi/UtilNode.py @@ -348,7 +348,7 @@ class SDBaseVerNumber: }, } - RETURN_TYPES = ("BOOLEAN", "BOOLEAN",) + RETURN_TYPES = ("BOOLEAN", "BOOLEAN", "BOOLEAN", "BOOLEAN", "BOOLEAN") RETURN_NAMES = ("sd1.5", "sdxl", "aura", "flux", "hunyuan") FUNCTION = "exec" diff --git a/static/js/workflows.js b/static/js/workflows.js index 58bd2db..fd7838a 100644 --- a/static/js/workflows.js +++ b/static/js/workflows.js @@ -2,6 +2,19 @@ import { app } from "/scripts/app.js"; import { $el } from "/scripts/ui.js"; import { GroupNodeHandler } from '/extensions/core/groupNode.js' import { EasyApiDialog } from './dialog.js' +let ComfyButton, ComfySplitButton; +import('/scripts/ui/components/button.js').then(module => { + ComfyButton = module.ComfyButton; +}).catch(error => { + // console.error('模块导入失败:', error); +}); +import('/scripts/ui/components/splitButton.js').then(module => { + ComfySplitButton = module.ComfySplitButton; +}).catch(error => { + // console.error('模块导入失败:', error); +}); + + const style = ` #comfy-save-button, #comfy-dev-save-api-button { @@ -205,6 +218,101 @@ class EasyApiWorkflows { ]; }); + // for new menu ui + if (!!app.menu && !!ComfyButton) { + const getCopyButton = (t) => + new ComfyButton({ + icon: "content-copy", + tooltip: "Copy the current workflow", + action: async () => { + app.graphToPrompt().then(p => { + const json = JSON.stringify(p.workflow, null, null); + copyToClipboard(json); + showTip("Copied") + }); + }, + content: t, + }); + let copyButton = new ComfySplitButton( + { + primary: getCopyButton(), + mode: "hover", + position: "absolute", + }, + getCopyButton("Copy"), + new ComfyButton({ + icon: "api", + content: "Copy (API Format)", + tooltip: "Copy the current workflow as JSON for use with the ComfyUI API", + action: async () => { + app.graphToPrompt().then(p => { + const apiObj = p.output; + const json = JSON.stringify(apiObj, null, null); + copyToClipboard(json); + showTip("Copied") + }); + }, + visibilitySetting: { id: "Comfy.DevMode", showValue: true }, + app, + }), + new ComfyButton({ + icon: "api", + content: "Copy to Base64 (API Format)", + tooltip: "Copy the current workflow as JSON for use with the ComfyUI API, replace input and output image nodes with base64 nodes", + action: async () => { + app.graphToPrompt().then(p => { + const apiObj = p.output; + const newApiObj = replaceImageNode(apiObj) + const json = JSON.stringify(newApiObj, null, null); // convert the data to a JSON string + copyToClipboard(json); + showTip("Copied") + }); + }, + visibilitySetting: { id: "Comfy.DevMode", showValue: true }, + app, + }), + ); + app.menu.saveButton.element.after(copyButton.element); + + let oldItems = app.menu.saveButton.items; + let exportEasyApiButton = new ComfyButton({ + icon: "api", + content: "Export to Base64 (API Format)", + tooltip: "Export the current workflow as JSON for use with the ComfyUI API, replace input and output image nodes with base64 nodes", + action: async () => { + let filename = "workflow_api(base64).json"; + filename = prompt("Export workflow API (Replace LoadImage to Base64Image, PreviewImage/SaveImage to ImageToBase64) as:", filename); + if (!filename) return; + if (!filename.toLowerCase().endsWith(".json")) { + filename += ".json"; + } + + app.graphToPrompt().then(p => { + const apiObj = p.output; + const newApiObj = replaceImageNode(apiObj) + const json = JSON.stringify(newApiObj, null, null); // convert the data to a JSON string + const blob = new Blob([json], {type: "application/json"}); + const url = URL.createObjectURL(blob); + const a = $el("a", { + href: url, + download: filename, + style: {display: "none"}, + parent: document.body, + }); + a.click(); + setTimeout(function () { + a.remove(); + window.URL.revokeObjectURL(url); + }, 0); + }); + }, + visibilitySetting: { id: "Comfy.DevMode", showValue: true }, + app, + }) + oldItems.push(exportEasyApiButton); + app.menu.saveButton.items = oldItems; + } + const handleFile = app.handleFile; const self = this; app.handleFile = function (file) {