From ddebbd40ea9ef4667a75b140f2c264d74213bd4d Mon Sep 17 00:00:00 2001 From: Adam Lamers Date: Mon, 4 May 2026 16:38:25 -0400 Subject: [PATCH] show directory sizes --- backend/app/api/inventory.py | 11 +++++++++-- .../components/file-browser/FileBrowserRowItem.svelte | 2 +- frontend/src/lib/utils.ts | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/app/api/inventory.py b/backend/app/api/inventory.py index b7fe62d..95400c3 100644 --- a/backend/app/api/inventory.py +++ b/backend/app/api/inventory.py @@ -715,7 +715,8 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d JOIN storage_media sm ON sm.id = fv.media_id JOIN filesystem_state fs2 ON fs2.id = fv.filesystem_state_id WHERE (fs2.file_path = :r OR fs2.file_path LIKE :prefix)) as media_list, - SUM(CASE WHEN EXISTS(SELECT 1 FROM restore_cart rc WHERE rc.filesystem_state_id = fs.id) THEN 1 ELSE 0 END) as selected_count + SUM(CASE WHEN EXISTS(SELECT 1 FROM restore_cart rc WHERE rc.filesystem_state_id = fs.id) THEN 1 ELSE 0 END) as selected_count, + SUM(fs.size) as total_size FROM filesystem_state fs WHERE (fs.file_path = :r OR fs.file_path LIKE :prefix) """) @@ -727,11 +728,13 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d protected = 0 media_list = [] selected_count = 0 + total_size = 0 if stats: total = stats[0] or 0 protected = stats[1] or 0 media_list = stats[2].split(",") if stats[2] else [] selected_count = stats[3] or 0 + total_size = stats[4] or 0 if protected > 0: results.append( @@ -739,6 +742,7 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d "name": root, "path": root, "type": "directory", + "size": total_size, "vulnerable": (protected < total), "selected": ( selected_count > 0 and selected_count == protected @@ -764,7 +768,8 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d JOIN storage_media sm ON sm.id = fv.media_id JOIN filesystem_state fs2 ON fs2.id = fv.filesystem_state_id WHERE fs2.file_path LIKE :prefix || SUBSTR(file_path, LENGTH(:prefix) + 1, INSTR(SUBSTR(file_path, LENGTH(:prefix) + 1), '/') - 1) || '/%') as media_list, - SUM(CASE WHEN EXISTS(SELECT 1 FROM restore_cart rc WHERE rc.filesystem_state_id = filesystem_state.id) THEN 1 ELSE 0 END) as selected_count + SUM(CASE WHEN EXISTS(SELECT 1 FROM restore_cart rc WHERE rc.filesystem_state_id = filesystem_state.id) THEN 1 ELSE 0 END) as selected_count, + SUM(size) as total_size FROM filesystem_state WHERE file_path LIKE :prefix_wildcard AND file_path != :prefix @@ -804,6 +809,7 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d protected = d[2] or 0 media_list = d[3].split(",") if d[3] else [] selected_count = d[4] or 0 + total_size = d[5] or 0 # Only show directories that have at least one protected file if protected == 0: @@ -815,6 +821,7 @@ def browse_archive_index(path: str = "ROOT", db_session: Session = Depends(get_d "name": d[0], "path": full_dir_path, "type": "directory", + "size": total_size, "vulnerable": (protected < total), "selected": (selected_count > 0 and selected_count == protected), "indeterminate": (selected_count > 0 and selected_count < protected), diff --git a/frontend/src/lib/components/file-browser/FileBrowserRowItem.svelte b/frontend/src/lib/components/file-browser/FileBrowserRowItem.svelte index 1c46256..149c697 100644 --- a/frontend/src/lib/components/file-browser/FileBrowserRowItem.svelte +++ b/frontend/src/lib/components/file-browser/FileBrowserRowItem.svelte @@ -255,7 +255,7 @@ class="shrink-0 px-4 h-full flex items-center justify-end text-xs text-text-secondary mono text-right tabular-nums font-medium border-r border-border-color/10" style="width: {colWidths.size}px" > - {item.type === "directory" ? "" : formatSize(item.size)} + {formatSize(item.size)} diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 3f3ce19..26d4775 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -43,8 +43,9 @@ export function formatLocalDateTime(dateStr: string | null | undefined): string * Formats a byte count into a human-readable string (KB, MB, GB, TB). * (MEDIUM #28 — consolidated from 5+ duplicate implementations) */ -export function formatSize(bytes: number): string { +export function formatSize(bytes: number | null | undefined): string { if (bytes === 0) return "0 B"; + if (!bytes) return "—"; const units = ["B", "KB", "MB", "GB", "TB"]; let unitIndex = 0; let size = bytes;