Skip to content

Commit

Permalink
Enables a way to save workflows in api format in frontend.
Browse files Browse the repository at this point in the history
Enable the dev mode in the settings to see it.
  • Loading branch information
comfyanonymous committed Jul 14, 2023
1 parent bdba394 commit 8a57796
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions web/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,37 @@ export class ComfyUI {
}, 0);
},
}),
$el("button", {
id: "comfy-dev-save-api-button",
textContent: "Save (API Format)",
style: {width: "100%", display: "none"},
onclick: () => {
let filename = "workflow_api.json";
if (promptFilename.value) {
filename = prompt("Save workflow (API) as:", filename);
if (!filename) return;
if (!filename.toLowerCase().endsWith(".json")) {
filename += ".json";
}
}
app.graphToPrompt().then(p=>{
const json = JSON.stringify(p.output, 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);
});
},
}),
$el("button", {id: "comfy-load-button", textContent: "Load", onclick: () => fileInput.click()}),
$el("button", {
id: "comfy-refresh-button",
Expand All @@ -694,6 +725,14 @@ export class ComfyUI {
}),
]);

const devMode = this.settings.addSetting({
id: "Comfy.DevMode",
name: "Enable Dev mode Options",
type: "boolean",
defaultValue: false,
onChange: function(value) { document.getElementById("comfy-dev-save-api-button").style.display = value ? "block" : "none"},
});

dragElement(this.menuContainer, this.settings);

this.setStatus({exec_info: {queue_remaining: "X"}});
Expand Down

0 comments on commit 8a57796

Please sign in to comment.