From 182a2cf197aaa1f2cf4d06af6dfc5bc85365d378 Mon Sep 17 00:00:00 2001 From: huyunan Date: Fri, 22 Mar 2024 08:16:33 +0000 Subject: [PATCH] share to esheep --- __init__.py | 15 +++++++++++++- js/comfyui-manager.js | 9 +++++++++ js/comfyui-share-common.js | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index ab8d62f8..b2c92ed0 100644 --- a/__init__.py +++ b/__init__.py @@ -831,7 +831,6 @@ def nickname_filter(json_obj): return json_obj - @server.PromptServer.instance.routes.get("/customnode/getmappings") async def fetch_customnode_mappings(request): mode = request.rel_url.query["mode"] @@ -2127,6 +2126,20 @@ async def api_get_comfyworkflows_auth(request): return web.Response(status=404) return web.json_response({"comfyworkflows_sharekey" : comfyworkflows_auth}) +@server.PromptServer.instance.routes.post("/manager/set_esheep_workflow_and_images") +async def set_esheep_workflow_and_images(request): + json_data = await request.json() + current_workflow = json_data['workflow'] + images = json_data['images'] + with open(os.path.join(comfyui_manager_path, "esheep_share_message.json"), "w", encoding='utf-8') as file: + json.dump(json_data, file, indent=4) + return web.Response(status=200) + +@server.PromptServer.instance.routes.get("/manager/get_esheep_workflow_and_images") +async def get_esheep_workflow_and_images(request): + with open(os.path.join(comfyui_manager_path, "esheep_share_message.json"), 'r', encoding='utf-8') as file: + data = json.load(file) + return web.Response(status=200, text=json.dumps(data)) def set_matrix_auth(json_data): homeserver = json_data['homeserver'] diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index 7cbd8dd4..52ee03ec 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -1174,6 +1174,15 @@ class ManagerMenuDialog extends ComfyDialog { ShareDialogChooser.instance.show(); }, }, + { + title: "Open 'esheep 电子羊'", + callback: () => { + const url = "https://www.esheep.com"; + localStorage.setItem("wg_last_visited", url); + window.open(url, url); + modifyButtonStyle(url); + }, + }, { title: "Open 'openart.ai'", callback: () => { diff --git a/js/comfyui-share-common.js b/js/comfyui-share-common.js index 74ab6af6..380130b6 100644 --- a/js/comfyui-share-common.js +++ b/js/comfyui-share-common.js @@ -164,6 +164,35 @@ export function parseURLPath(urlPath) { } +export const shareToEsheep= () => { + // 1、获得workflow和图片信息 + app.graphToPrompt() + .then(prompt => { + const nodes = app.graph._nodes + const { potential_outputs, potential_output_nodes } = getPotentialOutputsAndOutputNodes(nodes); + const workflow = prompt['workflow'] + // 2、把workflow和图片保存到本地 + api.fetchApi(`/manager/set_esheep_workflow_and_images`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + workflow: workflow, + images: potential_outputs + }) + }).then(response => { + // 获取域名(不包含子域) + var domain = window.location.hostname; + // 获取端口号 + var port = window.location.port; + // 如果端口为空字符串,则可能是使用了标准端口(80 for http and 443 for https) + port = port || (window.location.protocol === 'http:' ? '80' : window.location.protocol === 'https:' ? '443' : ''); + var full_domin = domain + ':' + port + // 打开新tab + window.open('https://www.esheep.com/app/workflow_upload?from_local='+ full_domin, '_blank'); + }); + }) +} + export const showOpenArtShareDialog = () => { if (!OpenArtShareDialog.instance) { OpenArtShareDialog.instance = new OpenArtShareDialog(); @@ -241,6 +270,17 @@ export class ShareDialogChooser extends ComfyDialog { } createButtons() { const buttons = [ + { + key: "esheep", + textContent: "eSheep 电子羊", + website: "https://www.esheep.com", + description: "在电子羊社区体验工作流免费分享与下载 \n\ + Share & download thousands of ComfyUI workflows on esheep.com", + onclick: () => { + shareToEsheep(); + this.close(); + } + }, { key: "openart", textContent: "OpenArt AI",