adds setting for filename prompt

This commit is contained in:
EllangoK 2023-04-14 23:07:27 -04:00
parent 4aa9afe21a
commit bb12418e66

View File

@ -431,6 +431,13 @@ export class ComfyUI {
defaultValue: true, defaultValue: true,
}); });
const promptFilename = this.settings.addSetting({
id: "Comfy.PromptFilename",
name: "Prompt for filename when saving workflow",
type: "boolean",
defaultValue: true,
});
const fileInput = $el("input", { const fileInput = $el("input", {
id: "comfy-file-input", id: "comfy-file-input",
type: "file", type: "file",
@ -524,20 +531,20 @@ export class ComfyUI {
id: "comfy-save-button", id: "comfy-save-button",
textContent: "Save", textContent: "Save",
onclick: () => { onclick: () => {
const defaultFileName = "workflow.json"; let filename = "workflow.json";
const userFileName = prompt("Save workflow as:", defaultFileName); if (promptFilename.value) {
if (userFileName === null) return; filename = prompt("Save workflow as:", filename);
let fileName = userFileName ? userFileName : defaultFileName; if (filename === null) return;
if (!filename.endsWith(".json")) {
if (!fileName.endsWith(".json")) { filename += ".json";
fileName += ".json"; }
} }
const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string 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 blob = new Blob([json], { type: "application/json" });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const a = $el("a", { const a = $el("a", {
href: url, href: url,
download: fileName, download: filename,
style: { display: "none" }, style: { display: "none" },
parent: document.body, parent: document.body,
}); });