mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-10 13:32:36 +08:00
Fix image extra output filename
This commit is contained in:
parent
63abeac497
commit
d05f12a4b8
@ -1,15 +1,13 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { hook } from "../../scripts/utils.js";
|
||||
|
||||
// Use widget values and dates in output filenames
|
||||
|
||||
/*
|
||||
app.registerExtension({
|
||||
name: "Comfy.SaveImageExtraOutput",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "SaveImage") {
|
||||
const onNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
|
||||
// Simple date formatter
|
||||
// Simple date formatter
|
||||
const parts = {
|
||||
d: (d) => d.getDate(),
|
||||
M: (d) => d.getMonth() + 1,
|
||||
@ -18,9 +16,9 @@ app.registerExtension({
|
||||
s: (d) => d.getSeconds(),
|
||||
};
|
||||
const format =
|
||||
Object.keys(parts)
|
||||
.map((k) => k + k + "?")
|
||||
.join("|") + "|yyy?y?";
|
||||
Object.keys(parts)
|
||||
.map((k) => k + k + "?")
|
||||
.join("|") + "|yyy?y?";
|
||||
|
||||
function formatDate(text, date) {
|
||||
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
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
|
||||
// When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R
|
||||
hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) {
|
||||
const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined;
|
||||
|
||||
const widget = this.widgets.find((w) => w.name === "filename_prefix");
|
||||
widget.serializeValue = () => {
|
||||
return widget.value.replace(/%([^%]+)%/g, function (match, text) {
|
||||
const split = text.split(".");
|
||||
if (split.length !== 2) {
|
||||
// Special handling for dates
|
||||
// Special handling for dates
|
||||
if (split[0].startsWith("date:")) {
|
||||
return formatDate(split[0].substring(5), new Date());
|
||||
}
|
||||
@ -83,20 +81,18 @@ app.registerExtension({
|
||||
};
|
||||
|
||||
return r;
|
||||
};
|
||||
});
|
||||
} else {
|
||||
// When any other node is created add a property to alias the node
|
||||
const onNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
|
||||
// When any other node is created add a property to alias the node
|
||||
hook(nodeType.class, "onNodeCreated", function (origOnNodeCreated, args) {
|
||||
const r = origOnNodeCreated ? origOnNodeCreated.apply(this, args) : undefined;
|
||||
|
||||
if (!this.properties || !("Node name for S&R" in this.properties)) {
|
||||
this.addProperty("Node name for S&R", this.constructor.type, "string");
|
||||
if (!this.hasProperty("Node name for S&R")) {
|
||||
this.addProperty("Node name for S&R", this.type, "string");
|
||||
}
|
||||
|
||||
return r;
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
*/
|
||||
|
||||
@ -2006,12 +2006,13 @@ const Ne = class {
|
||||
}
|
||||
/** sets the value of a property */
|
||||
setProperty(t, e) {
|
||||
var r;
|
||||
if (this.properties || (this.properties = {}), e !== 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)
|
||||
for (var n = 0; n < this.widgets.length; ++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;
|
||||
break;
|
||||
}
|
||||
@ -2452,6 +2453,9 @@ const Ne = class {
|
||||
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;
|
||||
}
|
||||
hasProperty(t) {
|
||||
return this.properties != null && t in this.properties;
|
||||
}
|
||||
/**
|
||||
* add a new output slot to use in this node
|
||||
* @param name
|
||||
|
||||
Loading…
Reference in New Issue
Block a user