(img, workflow)
| 218 | let workflows; |
| 219 | |
| 220 | async function sendToWorkflow(img, workflow) { |
| 221 | const graph = !workflow ? app.graph.serialize() : await getWorkflow(workflow); |
| 222 | const nodes = graph.nodes.filter((n) => n.type === "LoadImage"); |
| 223 | let targetNode; |
| 224 | if (nodes.length === 0) { |
| 225 | alert("To send the image to another workflow, that workflow must have a LoadImage node."); |
| 226 | return; |
| 227 | } else if (nodes.length > 1) { |
| 228 | targetNode = nodes.find((n) => n.title?.toLowerCase().includes("input")); |
| 229 | if (!targetNode) { |
| 230 | targetNode = nodes[0]; |
| 231 | alert( |
| 232 | "The target workflow has multiple LoadImage nodes, include 'input' in the name of the one you want to use. The first one will be used here." |
| 233 | ); |
| 234 | } |
| 235 | } else { |
| 236 | targetNode = nodes[0]; |
| 237 | } |
| 238 | |
| 239 | const blob = await (await fetch(img.src)).blob(); |
| 240 | const name = |
| 241 | (workflow || "sendtoworkflow").replace(/\//g, "_") + |
| 242 | "-" + |
| 243 | +new Date() + |
| 244 | new URLSearchParams(img.src.split("?")[1]).get("filename"); |
| 245 | const body = new FormData(); |
| 246 | body.append("image", new File([blob], name)); |
| 247 | |
| 248 | const resp = await api.fetchApi("/upload/image", { |
| 249 | method: "POST", |
| 250 | body, |
| 251 | }); |
| 252 | |
| 253 | if (resp.status === 200) { |
| 254 | await refreshComboInNodes.call(app); |
| 255 | targetNode.widgets_values[0] = name; |
| 256 | app.loadGraphData(graph); |
| 257 | app.graph.getNodeById(targetNode.id); |
| 258 | } else { |
| 259 | alert(resp.status + " - " + resp.statusText); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | app.registerExtension({ |
| 264 | name: "pysssss.Workflows", |
no test coverage detected