From ffcdbcf046075de32b66d8097be9496006b25270 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 26 Apr 2025 23:23:51 -0600 Subject: [PATCH] Enhance backup restoration UI and API by adding file size formatting, improving search debounce timing, and updating file listing to include additional metadata. Refactor file handling to ensure proper path resolution and error handling during JSON parsing. --- .../database/backups/restore-backup.tsx | 69 ++++++++++++++----- apps/dokploy/server/api/routers/backup.ts | 41 +++++++++-- 2 files changed, 84 insertions(+), 26 deletions(-) diff --git a/apps/dokploy/components/dashboard/database/backups/restore-backup.tsx b/apps/dokploy/components/dashboard/database/backups/restore-backup.tsx index 797e1ca8..69d37935 100644 --- a/apps/dokploy/components/dashboard/database/backups/restore-backup.tsx +++ b/apps/dokploy/components/dashboard/database/backups/restore-backup.tsx @@ -77,6 +77,14 @@ const RestoreBackupSchema = z.object({ type RestoreBackup = z.infer; +const formatBytes = (bytes: number): string => { + if (bytes === 0) return "0 Bytes"; + const k = 1024; + const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`; +}; + export const RestoreBackup = ({ databaseId, databaseType, @@ -101,7 +109,7 @@ export const RestoreBackup = ({ const debouncedSetSearch = debounce((value: string) => { setDebouncedSearchTerm(value); - }, 150); + }, 350); const handleSearchChange = (value: string) => { setSearch(value); @@ -271,7 +279,7 @@ export const RestoreBackup = ({ )} - +