refactor: reuse shared frontend path identity

This commit is contained in:
Dariusz L
2026-08-07 02:56:10 +02:00
parent 28af2d9e61
commit e485b467cc
3 changed files with 9 additions and 23 deletions
@@ -2064,9 +2064,6 @@ test('Power Lora Loader strength updates only its Loaded Models chip and cache',
const updateLoadedModelStrengthsFromNode = eval(
`(${extractMethod(tabsLoadedMethodsSource, 'updateLoadedModelStrengthsFromNode')})`
);
const normalizeLoadedModelIdentity = eval(
`(${extractMethod(tabsLoadedMethodsSource, 'normalizeLoadedModelIdentity')})`
);
const getLoadedModelDomKey = eval(
`(${extractMethod(tabsLoadedMethodsSource, 'getLoadedModelDomKey')})`
);
@@ -2100,7 +2097,6 @@ test('Power Lora Loader strength updates only its Loaded Models chip and cache',
},
cachedLoadedModelsSignature: 'old-signature',
activeWorkflowSignature: 'old-signature',
normalizeLoadedModelIdentity,
getLoadedModelDomKey,
getMissingModelKey: () => 'model-key',
updateLoadedModelCopyValues: (_container, models) => {
+6 -10
View File
@@ -1,8 +1,4 @@
import { getFilenameFromPath } from './utils/html_utils.js';
function normalizeIdentity(value) {
return String(value ?? '').trim().replaceAll('\\', '/').toLowerCase();
}
import { getFilenameFromPath, normalizePathIdentity } from './utils/html_utils.js';
function getResolvedModelPath(model = {}) {
return String(model.full_path || model.path || model.resolved_path || '').trim();
@@ -44,7 +40,7 @@ function getWidgetChoiceValue(choice) {
}
function isCurrentWidgetSelection(widget, value) {
const normalizedValue = normalizeIdentity(value);
const normalizedValue = normalizePathIdentity(value);
if (!normalizedValue || ['none', 'null', 'undefined'].includes(normalizedValue)) {
return false;
}
@@ -54,7 +50,7 @@ function isCurrentWidgetSelection(widget, value) {
return true;
}
return choices.some(choice => (
normalizeIdentity(getWidgetChoiceValue(choice)) === normalizedValue
normalizePathIdentity(getWidgetChoiceValue(choice)) === normalizedValue
));
}
@@ -108,7 +104,7 @@ export function matchesWorkflowModelReference(model = {}, reference = {}) {
}
if (reference.original_path) {
return normalizeIdentity(model.original_path) === normalizeIdentity(reference.original_path);
return normalizePathIdentity(model.original_path) === normalizePathIdentity(reference.original_path);
}
return true;
@@ -162,7 +158,7 @@ export function getImmediateModelsForNode(data = {}, node = {}, scope = {}) {
if (typeof currentValue !== 'string') continue;
if (!isCurrentWidgetSelection(widget, currentValue)) continue;
if (normalizeIdentity(currentValue) === normalizeIdentity(reference.original_path)) {
if (normalizePathIdentity(currentValue) === normalizePathIdentity(reference.original_path)) {
if (isExistingResolvedModel(reference)) {
modelsByWidget.set(widgetIndex, reference);
}
@@ -201,7 +197,7 @@ function getSubgraphModelReferenceKey(model = {}) {
model.subgraph_id || '',
model.node_id ?? '',
model.widget_index ?? '',
normalizeIdentity(model.original_path || model.name || ''),
normalizePathIdentity(model.original_path || model.name || ''),
].join('|');
}
+3 -9
View File
@@ -3,6 +3,7 @@ import {
getCustomNodeModelEntries,
getCustomNodeOriginalIdentity,
} from "../custom_nodes/registry.js";
import { normalizePathIdentity } from "../utils/html_utils.js";
export const tabsLoadedMethods = {
getTabButton(tab) {
return {
@@ -203,13 +204,6 @@ export const tabsLoadedMethods = {
return this.getMissingModelKey(model);
},
normalizeLoadedModelIdentity(value) {
return String(value || '')
.trim()
.replace(/\\/g, '/')
.toLowerCase();
},
updateLoadedModelCopyValues(container, loadedModels = []) {
if (!container) return;
@@ -291,7 +285,7 @@ export const tabsLoadedMethods = {
const entries = getCustomNodeModelEntries(node)
.filter(entry => Number.isFinite(entry.strength))
.map(entry => ({
identity: this.normalizeLoadedModelIdentity(entry.identity),
identity: normalizePathIdentity(entry.identity),
strength: entry.strength,
}));
if (!entries.length) return false;
@@ -300,7 +294,7 @@ export const tabsLoadedMethods = {
const modelBuckets = new Map();
for (const model of this.cachedLoadedModelsData.loaded_models) {
if (String(model.node_id ?? '') !== nodeId) continue;
const identity = this.normalizeLoadedModelIdentity(
const identity = normalizePathIdentity(
getCustomNodeOriginalIdentity(model)
|| model.original_path
|| model.name