Skip to content

Commit

Permalink
Apply primitive nodes to graph before serializing workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Oct 26, 2023
1 parent 723847f commit 40963b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
14 changes: 10 additions & 4 deletions web/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1586,17 +1586,23 @@ export class ComfyApp {
* @returns The workflow and node links
*/
async graphToPrompt() {
for (const node of this.graph.computeExecutionOrder(false)) {
if (node.isVirtualNode) {
// Don't serialize frontend only nodes but let them make changes
if (node.applyToGraph) {
node.applyToGraph();
}
continue;
}
}

const workflow = this.graph.serialize();
const output = {};
// Process nodes in order of execution
for (const node of this.graph.computeExecutionOrder(false)) {
const n = workflow.nodes.find((n) => n.id === node.id);

if (node.isVirtualNode) {
// Don't serialize frontend only nodes but let them make changes
if (node.applyToGraph) {
node.applyToGraph(workflow);
}
continue;
}

Expand Down
28 changes: 15 additions & 13 deletions web/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,20 +719,22 @@ export class ComfyUI {
filename += ".json";
}
}
const json = JSON.stringify(app.graph.serialize(), null, 2); // 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,
app.graphToPrompt().then(p=>{
const json = JSON.stringify(p.workflow, null, 2); // 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);
});
a.click();
setTimeout(function () {
a.remove();
window.URL.revokeObjectURL(url);
}, 0);
},
}),
$el("button", {
Expand Down

0 comments on commit 40963b5

Please sign in to comment.