refactor: Extract isNodeEnabled helper to eliminate mode check duplication

Consolidate node enabled state checks into isNodeEnabled() helper function
to improve code clarity and maintainability. Follows DRY principle.
This commit is contained in:
Will Miao
2026-02-23 16:47:09 +08:00
parent 7a04cec08d
commit f1eb89af7a

View File

@@ -457,6 +457,14 @@ function getWidgetNames(node) {
return []; return [];
} }
function isNodeEnabled(node) {
if (!node) {
return false;
}
// ComfyUI node mode: 0 = Normal/Enabled, others = Always/Never/OnEvent
return node.mode === undefined || node.mode === 0;
}
function isAbsolutePath(path) { function isAbsolutePath(path) {
if (typeof path !== 'string') { if (typeof path !== 'string') {
return false; return false;
@@ -507,10 +515,7 @@ export async function sendLoraToWorkflow(loraSyntax, replaceMode = false, syntax
} }
const loraNodes = filterRegistryNodes(registry.nodes, (node) => { const loraNodes = filterRegistryNodes(registry.nodes, (node) => {
if (!node) { if (!isNodeEnabled(node)) {
return false;
}
if (node.mode !== undefined && node.mode !== 0) {
return false; return false;
} }
if (node.capabilities && typeof node.capabilities === 'object') { if (node.capabilities && typeof node.capabilities === 'object') {
@@ -572,10 +577,7 @@ export async function sendModelPathToWorkflow(modelPath, options) {
} }
const targetNodes = filterRegistryNodes(registry.nodes, (node) => { const targetNodes = filterRegistryNodes(registry.nodes, (node) => {
if (!node) { if (!isNodeEnabled(node)) {
return false;
}
if (node.mode !== undefined && node.mode !== 0) {
return false; return false;
} }
const widgetNames = getWidgetNames(node); const widgetNames = getWidgetNames(node);