ui_gallery_viewer.js (8c044d0) imported formatSize from
ui_model_download.js, which leads through the settings page and
browser.js back to ui_ai_workbench.js; with ui_ai_images.js ->
ui_gallery_detail.js -> ui_gallery_viewer.js at the start of that chain,
ui_ai_workbench.js called setMarker before ui_ai_images.js had run, and
the whole plugin failed to load ("Cannot access 'marker' before
initialization"). formatSize now lives in file_size.js, which imports
nothing, and every module takes it from there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 lines
379 B
JavaScript
8 lines
379 B
JavaScript
/** A file's size in words people read: KB, MB or GB. No imports, so any module can use it. */
|
|
export function formatSize(bytes) {
|
|
const value = Number(bytes) || 0;
|
|
if (value >= 1024 ** 3) return `${(value / 1024 ** 3).toFixed(2)} GB`;
|
|
if (value >= 1024 ** 2) return `${(value / 1024 ** 2).toFixed(1)} MB`;
|
|
return `${Math.max(1, Math.round(value / 1024))} KB`;
|
|
}
|