Add accumulator retake workflow restore
This commit is contained in:
@@ -247,6 +247,24 @@ async function postJson(path, payload) {
|
||||
return data;
|
||||
}
|
||||
|
||||
function workflowFromRetakeData(data) {
|
||||
const workflow = data?.workflow;
|
||||
if (!workflow) throw new Error("No workflow metadata found on this accumulator entry.");
|
||||
if (typeof workflow === "string") return JSON.parse(workflow);
|
||||
return workflow;
|
||||
}
|
||||
|
||||
async function loadWorkflow(workflow) {
|
||||
if (typeof app.loadGraphData === "function") {
|
||||
await app.loadGraphData(workflow);
|
||||
return;
|
||||
}
|
||||
if (!app.graph?.configure) throw new Error("This ComfyUI frontend cannot load workflow data.");
|
||||
app.graph.clear?.();
|
||||
app.graph.configure(workflow);
|
||||
app.graph.setDirtyCanvas?.(true, true);
|
||||
}
|
||||
|
||||
function injectStyles() {
|
||||
if (document.getElementById(STYLE_ID)) return;
|
||||
const css = `
|
||||
@@ -421,6 +439,12 @@ function renderCell(node, entry, imageParams, displayIndex, options = {}) {
|
||||
}
|
||||
thumb.draggable = true;
|
||||
thumb.onclick = () => markSelected(node, entry.index);
|
||||
thumb.oncontextmenu = async (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
markSelected(node, entry.index);
|
||||
await retakeEntry(node, entry);
|
||||
};
|
||||
thumb.ondragstart = (event) => {
|
||||
node._sxapDragEntry = entry;
|
||||
debugLog("dragstart", {index: entry.index, key: entryKey(entry), id: entry.id});
|
||||
@@ -444,7 +468,7 @@ function renderCell(node, entry, imageParams, displayIndex, options = {}) {
|
||||
const meta = document.createElement("div");
|
||||
meta.className = "sxap-meta";
|
||||
meta.textContent = "M";
|
||||
meta.title = "has metadata";
|
||||
meta.title = "has metadata; right-click image to retake";
|
||||
cell.appendChild(meta);
|
||||
}
|
||||
|
||||
@@ -668,6 +692,34 @@ async function saveBatch(node) {
|
||||
}
|
||||
}
|
||||
|
||||
async function retakeEntry(node, entry) {
|
||||
const key = storeKey(node);
|
||||
if (!key) {
|
||||
alert("Set the same explicit store_key on the Accumulator and Accumulator Preview first.");
|
||||
return;
|
||||
}
|
||||
if (!entry) return;
|
||||
if (!entry.has_metadata) {
|
||||
alert("This accumulator entry has no metadata to retake from.");
|
||||
return;
|
||||
}
|
||||
const label = entry.id || `#${entry.index}`;
|
||||
if (!confirm(`Retake ${label}? This will replace the current workflow with the workflow metadata saved on that entry.`)) return;
|
||||
try {
|
||||
const data = await postJson("/sxcp/accumulator/retake", {
|
||||
store_key: key,
|
||||
preview_key: entry.preview_key || "",
|
||||
entry_id: entry.id || "",
|
||||
index: entry.preview_key || entry.id ? 0 : entry.index,
|
||||
});
|
||||
const workflow = workflowFromRetakeData(data);
|
||||
await loadWorkflow(workflow);
|
||||
} catch (err) {
|
||||
console.error(`[${EXTENSION}] retake failed`, err);
|
||||
alert(`Retake failed: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
function hideInternalWidgets(node) {
|
||||
for (const name of [
|
||||
"delete_action",
|
||||
|
||||
Reference in New Issue
Block a user