Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(web): delegate fallback formatFileSize to shared formatBytes (#7295)

Vladimir Babin2df1c3d165b8
diff --git a/changelog.d/6583.bugfix.md b/changelog.d/6583.bugfix.md
new file mode 100644
index 0000000000..cf20156aa8
--- /dev/null
+++ b/changelog.d/6583.bugfix.md
@@ -0,0 +1 @@
+The fallback `formatFileSize` now delegates to the shared `formatBytes` formatter, so non-finite and negative byte counts render as `0 Bytes` instead of `Infinity TB` / `-1.0 B`.
diff --git a/src/local_deep_research/web/static/js/components/fallback/formatting.js b/src/local_deep_research/web/static/js/components/fallback/formatting.js
index dc59eccaff..c1c743e87b 100644
--- a/src/local_deep_research/web/static/js/components/fallback/formatting.js
+++ b/src/local_deep_research/web/static/js/components/fallback/formatting.js
@@ -86,17 +86,7 @@
*/
function formatFileSize(bytes) {
if (!bytes && bytes !== 0) return 'N/A';
-
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
- let size = bytes;
- let unitIndex = 0;
-
- while (size >= 1024 && unitIndex < units.length - 1) {
- size /= 1024;
- unitIndex++;
- }
-
- return `${size.toFixed(1)} ${units[unitIndex]}`;
+ return window.formatBytes(bytes);
}
// Export utilities to window.formatting
diff --git a/tests/js/components/fallback-formatting.test.js b/tests/js/components/fallback-formatting.test.js
index 143c256d50..14fb5cb829 100644
--- a/tests/js/components/fallback-formatting.test.js
+++ b/tests/js/components/fallback-formatting.test.js
@@ -27,6 +27,9 @@ beforeAll(async () => {
// Load ResearchStates
await import('@js/config/constants.js');
+ // formatFileSize delegates to the shared window.formatBytes
+ await import('@js/utils/format-bytes.js');
+
// Delete any existing formatting to force fallback to activate
delete window.formatting;
@@ -100,28 +103,33 @@ describe('fallback formatting', () => {
});
it('formats bytes', () => {
- expect(fallbackFormatting.formatFileSize(500)).toBe('500.0 B');
+ expect(fallbackFormatting.formatFileSize(500)).toBe('500 Bytes');
});
it('formats kilobytes', () => {
- expect(fallbackFormatting.formatFileSize(1024)).toBe('1.0 KB');
+ expect(fallbackFormatting.formatFileSize(1024)).toBe('1 KB');
});
it('formats megabytes', () => {
- expect(fallbackFormatting.formatFileSize(1048576)).toBe('1.0 MB');
+ expect(fallbackFormatting.formatFileSize(1048576)).toBe('1 MB');
});
it('formats gigabytes', () => {
- expect(fallbackFormatting.formatFileSize(1073741824)).toBe('1.0 GB');
+ expect(fallbackFormatting.formatFileSize(1073741824)).toBe('1 GB');
});
it('handles zero bytes', () => {
- expect(fallbackFormatting.formatFileSize(0)).toBe('0.0 B');
+ expect(fallbackFormatting.formatFileSize(0)).toBe('0 Bytes');
});
it('formats with decimal precision', () => {
expect(fallbackFormatting.formatFileSize(1536)).toBe('1.5 KB');
});
+
+ it('clamps non-finite and negative inputs like the shared formatter', () => {
+ expect(fallbackFormatting.formatFileSize(Infinity)).toBe('0 Bytes');
+ expect(fallbackFormatting.formatFileSize(-1)).toBe('0 Bytes');
+ });
});
describe('formatStatus', () => {