From 478b2c61961665c6113a71223002262983974a05 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Mon, 5 Jan 2026 16:15:31 +0100 Subject: [PATCH] Add web/sync_menu.js --- web/sync_menu.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 web/sync_menu.js diff --git a/web/sync_menu.js b/web/sync_menu.js new file mode 100644 index 0000000..3cf2cbb --- /dev/null +++ b/web/sync_menu.js @@ -0,0 +1,58 @@ +import { app } from "../../scripts/app.js"; +import { api } from "../../scripts/api.js"; + +app.registerExtension({ + name: "Comfy.NetworkSync", + async setup() { + const menu = document.querySelector(".comfy-menu"); + + const syncButton = document.createElement("button"); + syncButton.textContent = "Sync to Network"; + syncButton.style.backgroundColor = "#2a4a75"; // Distinct blue color + syncButton.style.marginTop = "10px"; + + syncButton.onclick = async () => { + // 1. Get the workflow data + const workflow = await app.graphToPrompt(); + // Note: graphToPrompt gets the API format. + // If you want the editable format, use: app.graph.serialize() + const fullWorkflow = app.graph.serialize(); + + // 2. Get settings (Target IP) + let targetIP = localStorage.getItem("Comfy.NetworkSync.TargetIP"); + targetIP = prompt("Enter Target IP (e.g. 192.168.1.5:8188):", targetIP || ""); + + if (!targetIP) return; + localStorage.setItem("Comfy.NetworkSync.TargetIP", targetIP); + + // 3. Get Filename + let filename = prompt("Enter Workflow Name:", "synced_workflow"); + if (!filename) return; + + // 4. Send to Local Backend (which forwards to Remote) + try { + const response = await api.fetchApi("/network-sync/push", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + target_ip: targetIP, + name: filename, + workflow: fullWorkflow + }), + }); + + const result = await response.json(); + if (result.status === "success") { + alert("✅ Workflow Synced Successfully!"); + } else { + alert("❌ Error: " + result.message); + } + } catch (err) { + alert("❌ Connection Failed: " + err.message); + } + }; + + // Add after the "Save" button usually found in the menu + menu.append(syncButton); + }, +}); \ No newline at end of file