refactor: reuse missing category collector

This commit is contained in:
Dariusz L
2026-08-05 02:15:22 +02:00
parent e326a107f4
commit 8c47fe6da8
2 changed files with 47 additions and 22 deletions
@@ -5558,6 +5558,47 @@ test('download category normalization maps gguf folder keys to diffusion models'
assert.equal(normalizeDownloadCategory('model_gguf'), 'diffusion_models');
});
test('missing model categories preserve node priority and fallback order', () => {
const getMissingSupportedDownloadCategories = eval(
`(${extractMethod(downloadTargetMethodsSource, 'getMissingSupportedDownloadCategories')})`
);
const dialog = {
downloadDirectories: {
checkpoints: [],
loras: [],
vae: [],
},
getDefaultDownloadCategoryKeys() {
return [];
},
getKnownDownloadCategorySet() {
return new Set(Object.keys(this.downloadDirectories));
},
normalizeDownloadCategory(value = '') {
return String(value || '').trim().toLowerCase();
},
getMissingNodeTypeDownloadCategory(missing) {
return missing.node_category || '';
},
};
assert.deepEqual(
getMissingSupportedDownloadCategories.call(dialog, {
node_category: 'loras',
category: 'checkpoints',
directory: 'vae',
}),
['loras']
);
assert.deepEqual(
getMissingSupportedDownloadCategories.call(dialog, {
category: 'checkpoints, checkpoints',
directory: 'vae|loras',
}),
['checkpoints', 'vae', 'loras']
);
});
test('download category normalization maps select safetensors alias to diffusion models', () => {
const normalizeDownloadCategory = eval(`(${extractMethod(downloadTargetMethodsSource, 'normalizeDownloadCategory')})`);
+6 -22
View File
@@ -158,30 +158,14 @@ export const downloadTargetMethods = {
return chooseSupported(supported);
}
const fallbackSupported = [];
const addCategory = (value) => {
if (value === undefined || value === null || String(value).trim() === '') return;
if (Array.isArray(value)) {
value.forEach(addCategory);
return;
}
String(value).split(/[,|;]/).forEach(part => {
const normalized = this.normalizeDownloadCategory(part);
if (normalized && knownCategories.has(normalized) && !fallbackSupported.includes(normalized)) {
fallbackSupported.push(normalized);
}
});
};
addCategory(this.getMissingNodeTypeDownloadCategory(missing));
if (fallbackSupported.length) {
return fallbackSupported;
const nodeSupported = collectCategories(
this.getMissingNodeTypeDownloadCategory(missing)
);
if (nodeSupported.length) {
return nodeSupported;
}
addCategory(missing.category);
addCategory(missing.directory);
return fallbackSupported;
return collectCategories(missing.category, missing.directory);
},
getSourceResultDownloadCategory(source = {}, fallbackCategory = '', missing = null) {