fix(frontend): preserve model size across search result shapes

This commit is contained in:
Dariusz L
2026-08-04 21:02:43 +02:00
parent ab9d21bcb2
commit 0b82fe49ee
2 changed files with 67 additions and 3 deletions
@@ -5829,6 +5829,40 @@ test('search result table exposes linked local hash targets for exact matches',
assert.match(html, />Exact<\/span>/);
});
test('CivitAI hash search renders sizeKB when byte size is unavailable', () => {
const formatSearchResultSize = eval(`(${extractMethod(searchPanelMethodsSource, 'formatSearchResultSize')})`);
const dialog = {
formatBytes(value) {
const units = ['B', 'KB', 'MB', 'GB'];
let index = 0;
let number = Number(value);
while (number >= 1024 && index < units.length - 1) {
number /= 1024;
index += 1;
}
return `${Number(number.toFixed(1))} ${units[index]}`;
},
};
assert.equal(
formatSearchResultSize.call(dialog, {
source: 'civitai',
match_type: 'hash',
size: null,
sizeKB: 12021353.90625,
}),
'11.5 GB'
);
assert.equal(
formatSearchResultSize.call(dialog, {
source: 'civitai',
size: null,
files: [{ name: 'zImageTurbo_turbo.safetensors', sizeKB: 12021353.90625 }],
}),
'11.5 GB'
);
});
test('search result refreshes preserve keyed progress and result DOM', () => {
const displaySearchResults = extractMethod(resolveDownloadMethodsSource, 'displaySearchResults');
const patchSearchResultsContainer = extractMethod(
+33 -3
View File
@@ -1509,9 +1509,39 @@ export const searchPanelMethods = {
},
formatSearchResultSize(result = {}) {
if (result.size === 0) return '0 B';
if (!result.size) return '';
return typeof result.size === 'number' ? this.formatBytes(result.size) : String(result.size);
const candidates = [result];
const nestedCandidates = [
result.file_info,
result.fileInfo,
result.selected_file,
result.selectedFile,
];
const files = Array.isArray(result.files) ? result.files : [];
candidates.push(
...nestedCandidates.filter(candidate => candidate && typeof candidate === 'object'),
...files.filter(candidate => candidate && typeof candidate === 'object')
);
for (const candidate of candidates) {
const directSize = candidate.size
?? candidate.size_bytes
?? candidate.sizeBytes
?? candidate.file_size
?? candidate.fileSize
?? candidate.bytes;
if (directSize === 0) return '0 B';
if (directSize !== undefined && directSize !== null && directSize !== '') {
return typeof directSize === 'number' ? this.formatBytes(directSize) : String(directSize);
}
const sizeKb = candidate.sizeKB ?? candidate.size_kb;
if (sizeKb !== undefined && sizeKb !== null && sizeKb !== '') {
const sizeBytes = Number(sizeKb) * 1024;
if (Number.isFinite(sizeBytes)) return this.formatBytes(sizeBytes);
}
}
return '';
},
getSearchResultMatchDisplay(result = {}, fallbackLabel = 'Match', fallbackClass = 'neutral', hashLabel = '') {