Fix image extra output filename

This commit is contained in:
space-nuko 2023-08-23 11:42:40 -05:00
parent 63abeac497
commit d05f12a4b8
2 changed files with 21 additions and 21 deletions

View File

@ -1,15 +1,13 @@
import { app } from "../../scripts/app.js"; import { app } from "../../scripts/app.js";
import { hook } from "../../scripts/utils.js";
// Use widget values and dates in output filenames // Use widget values and dates in output filenames
/*
app.registerExtension({ app.registerExtension({
name: "Comfy.SaveImageExtraOutput", name: "Comfy.SaveImageExtraOutput",
async beforeRegisterNodeDef(nodeType, nodeData, app) { async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "SaveImage") { if (nodeData.name === "SaveImage") {
const onNodeCreated = nodeType.prototype.onNodeCreated; // Simple date formatter
// Simple date formatter
const parts = { const parts = {
d: (d) => d.getDate(), d: (d) => d.getDate(),
M: (d) => d.getMonth() + 1, M: (d) => d.getMonth() + 1,
@ -18,9 +16,9 @@ app.registerExtension({
s: (d) => d.getSeconds(), s: (d) => d.getSeconds(),
}; };
const format = const format =
Object.keys(parts) Object.keys(parts)
.map((k) => k + k + "?") .map((k) => k + k + "?")
.join("|") + "|yyy?y?"; .join("|") + "|yyy?y?";
function formatDate(text, date) { function formatDate(text, date) {
return text.replace(new RegExp(format, "g"), function (text) { return text.replace(new RegExp(format, "g"), function (text) {
@ -34,16 +32,16 @@ app.registerExtension({
}); });
} }
// When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R // When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R
nodeType.prototype.onNodeCreated = function () { hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) {
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined; const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined;
const widget = this.widgets.find((w) => w.name === "filename_prefix"); const widget = this.widgets.find((w) => w.name === "filename_prefix");
widget.serializeValue = () => { widget.serializeValue = () => {
return widget.value.replace(/%([^%]+)%/g, function (match, text) { return widget.value.replace(/%([^%]+)%/g, function (match, text) {
const split = text.split("."); const split = text.split(".");
if (split.length !== 2) { if (split.length !== 2) {
// Special handling for dates // Special handling for dates
if (split[0].startsWith("date:")) { if (split[0].startsWith("date:")) {
return formatDate(split[0].substring(5), new Date()); return formatDate(split[0].substring(5), new Date());
} }
@ -83,20 +81,18 @@ app.registerExtension({
}; };
return r; return r;
}; });
} else { } else {
// When any other node is created add a property to alias the node // When any other node is created add a property to alias the node
const onNodeCreated = nodeType.prototype.onNodeCreated; hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) {
nodeType.prototype.onNodeCreated = function () { const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined;
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
if (!this.properties || !("Node name for S&R" in this.properties)) { if (!this.hasProperty("Node name for S&R")) {
this.addProperty("Node name for S&R", this.constructor.type, "string"); this.addProperty("Node name for S&R", this.type, "string");
} }
return r; return r;
}; });
} }
}, },
}); });
*/

View File

@ -2006,12 +2006,13 @@ const Ne = class {
} }
/** sets the value of a property */ /** sets the value of a property */
setProperty(t, e) { setProperty(t, e) {
var r;
if (this.properties || (this.properties = {}), e !== this.properties[t]) { if (this.properties || (this.properties = {}), e !== this.properties[t]) {
var i = this.properties[t]; var i = this.properties[t];
if (this.properties[t] = e, this.graph && this.graph._version++, this.onPropertyChanged && this.onPropertyChanged(t, e, i) === !1 && (this.properties[t] = i), this.widgets) if (this.properties[t] = e, this.graph && this.graph._version++, this.onPropertyChanged && this.onPropertyChanged(t, e, i) === !1 && (this.properties[t] = i), this.widgets)
for (var n = 0; n < this.widgets.length; ++n) { for (var n = 0; n < this.widgets.length; ++n) {
var s = this.widgets[n]; var s = this.widgets[n];
if (s && s.options.property == t) { if (s && ((r = s.options) == null ? void 0 : r.property) == t) {
s.value = e; s.value = e;
break; break;
} }
@ -2452,6 +2453,9 @@ const Ne = class {
s[r] = n[r]; s[r] = n[r];
return this.properties_info || (this.properties_info = []), this.properties_info.push(s), this.properties || (this.properties = {}), this.properties[t] = e, s; return this.properties_info || (this.properties_info = []), this.properties_info.push(s), this.properties || (this.properties = {}), this.properties[t] = e, s;
} }
hasProperty(t) {
return this.properties != null && t in this.properties;
}
/** /**
* add a new output slot to use in this node * add a new output slot to use in this node
* @param name * @param name