diff --git a/webui/html/app.js b/webui/html/app.js
index c556e15..4543999 100644
--- a/webui/html/app.js
+++ b/webui/html/app.js
@@ -837,6 +837,25 @@ function formatModified(isoString) {
return `${date} ${time}`;
}
+function formatFileSize(bytes) {
+ if (typeof bytes !== "number" || !Number.isFinite(bytes) || bytes < 0) {
+ return "-";
+ }
+ if (bytes < 1024) {
+ return `${bytes} B`;
+ }
+ if (bytes < 1024 ** 2) {
+ return `${Math.round(bytes / 1024)} KB`;
+ }
+ if (bytes < 1024 ** 3) {
+ return `${(bytes / (1024 ** 2)).toFixed(1)} MB`;
+ }
+ if (bytes < 1024 ** 4) {
+ return `${(bytes / (1024 ** 3)).toFixed(1)} GB`;
+ }
+ return `${(bytes / (1024 ** 4)).toFixed(1)} TB`;
+}
+
function createBrowseItem(pane, entry, kind) {
const li = document.createElement("li");
li.className = "selectable";
@@ -888,7 +907,7 @@ function createBrowseItem(pane, entry, kind) {
const size = document.createElement("span");
size.className = "entry-size";
- size.textContent = kind === "directory" ? "-" : String(entry.size);
+ size.textContent = kind === "directory" ? "-" : formatFileSize(entry.size);
li.append(size);
const modified = document.createElement("span");