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); }, });