mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-22 12:57:02 +08:00
First version of code to save workflows in the app
This commit is contained in:
parent
fd7c636680
commit
aa2e2c02ff
@ -1,3 +1,16 @@
|
||||
export function load_saved() {
|
||||
try {
|
||||
let rv = JSON.parse(localStorage.getItem("saved") || "{}");
|
||||
return rv;
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function save_saved(list) {
|
||||
localStorage.setItem('saved', JSON.stringify(list));
|
||||
}
|
||||
|
||||
class ComfyApi extends EventTarget {
|
||||
#registered = new Set();
|
||||
|
||||
@ -231,10 +244,14 @@ class ComfyApi extends EventTarget {
|
||||
* @returns The items of the specified type grouped by their status
|
||||
*/
|
||||
async getItems(type) {
|
||||
if (type === "queue") {
|
||||
switch (type) {
|
||||
case "queue":
|
||||
return this.getQueue();
|
||||
case "history":
|
||||
return this.getHistory();
|
||||
case "saved":
|
||||
return this.getSaved();
|
||||
}
|
||||
return this.getHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,6 +297,39 @@ class ComfyApi extends EventTarget {
|
||||
async getSystemStats() {
|
||||
const res = await this.fetchApi("/system_stats");
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets prompts saved by the user
|
||||
* @returns Saved prompts with outputs
|
||||
*/
|
||||
async getSaved() {
|
||||
// note that this could, and maybe should, be persisted
|
||||
// server-side; however, the server doesn't have any persistence
|
||||
// yet, so rather than add a dependency on sqlite or whatever
|
||||
// I'll just use client storage for now
|
||||
try {
|
||||
const r = load_saved();
|
||||
console.log("r is", r);
|
||||
return { Saved: Object.values(r).map((i) => {
|
||||
console.log(i);
|
||||
i['remove'] = {
|
||||
name: "Delete",
|
||||
cb: () => {
|
||||
let name = i.prompt[0];
|
||||
let list = load_saved();
|
||||
if (list.hasOwnProperty(name)) {
|
||||
delete list[name];
|
||||
}
|
||||
save_saved(list);
|
||||
},
|
||||
};
|
||||
return i;
|
||||
})};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { Saved: [] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { api } from "./api.js";
|
||||
import { api, load_saved, save_saved } from "./api.js";
|
||||
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js";
|
||||
import { toggleSwitch } from "./ui/toggleSwitch.js";
|
||||
import { ComfySettingsDialog } from "./ui/settings.js";
|
||||
@ -294,10 +294,12 @@ export class ComfyUI {
|
||||
this.lastQueueSize = 0;
|
||||
this.queue = new ComfyList("Queue");
|
||||
this.history = new ComfyList("History", "history", true);
|
||||
this.saved = new ComfyList("Saved");
|
||||
|
||||
api.addEventListener("status", () => {
|
||||
this.queue.update();
|
||||
this.history.update();
|
||||
this.saved.update();
|
||||
});
|
||||
|
||||
const confirmClear = this.settings.addSetting({
|
||||
@ -521,9 +523,33 @@ export class ComfyUI {
|
||||
]),
|
||||
this.queue.element,
|
||||
this.history.element,
|
||||
this.saved.element,
|
||||
$el("button", {
|
||||
id: "comfy-save-local-button",
|
||||
textContent: "Save",
|
||||
onclick: () => {
|
||||
let name = prompt("Name:", "");
|
||||
let list = load_saved();
|
||||
const new_item = {
|
||||
prompt: [
|
||||
name,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
extra_pnginfo: {
|
||||
workflow: app.graph.serialize(),
|
||||
}
|
||||
}
|
||||
],
|
||||
outputs: app.nodeOutputs,
|
||||
};
|
||||
list[name] = new_item;
|
||||
save_saved(list);
|
||||
},
|
||||
}),
|
||||
$el("button", {
|
||||
id: "comfy-save-button",
|
||||
textContent: "Save",
|
||||
textContent: "Download",
|
||||
onclick: () => {
|
||||
let filename = "workflow.json";
|
||||
if (promptFilename.value) {
|
||||
@ -605,6 +631,7 @@ export class ComfyUI {
|
||||
}
|
||||
}),
|
||||
]);
|
||||
this.saved.show();
|
||||
|
||||
const devMode = this.settings.addSetting({
|
||||
id: "Comfy.DevMode",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user