mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-12 15:20:51 +08:00
* Security filter of workflow - if there are image files or model files in the config, they will be converted into an empty array.
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
// If there are files with specific extensions in the array inside the config of nodes/inputs/widget in the workflow, empty that array.
|
|
const excludeExtensions = new Set(["png", "jpg", "webp", "jpeg", "safetensors", "ckpt", "pt", "pth"]);
|
|
|
|
function getFileExtension(filename) {
|
|
return filename.slice((filename.lastIndexOf('.') - 1 >>> 0) + 2);
|
|
}
|
|
|
|
export class Util {
|
|
static workflow_security_filter(workflow) {
|
|
workflow.nodes.forEach((node) => {
|
|
if (node.inputs) {
|
|
node.inputs.forEach((input) => {
|
|
if (input.widget && input.widget.config) {
|
|
const configArray = input.widget.config[0];
|
|
if (Array.isArray(configArray) && configArray.every((filename) => excludeExtensions.has(getFileExtension(filename)))) {
|
|
input.widget.config[0] = [];
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if (node.outputs) {
|
|
node.outputs.forEach((output) => {
|
|
if (output.widget && output.widget.config) {
|
|
const configArray = output.widget.config[0];
|
|
if (Array.isArray(configArray) && configArray.every((filename) => excludeExtensions.has(getFileExtension(filename)))) {
|
|
output.widget.config[0] = [];
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
return workflow;
|
|
}
|
|
};
|