From 02b25ce047eb50d17ae550d175e2ffde7bec59b7 Mon Sep 17 00:00:00 2001 From: vishalkadam47 Date: Sun, 1 Jun 2025 04:26:21 +0530 Subject: [PATCH] refactor: clean up cloud storage components --- .../backups/cloud-storage/show-cloud-backups.tsx | 3 ++- .../destination/cloud-storage-destinations.tsx | 2 +- .../server/api/routers/cloud-storage-backup.ts | 16 +++++++++++++--- .../api/routers/cloud-storage-destination.ts | 4 ++-- .../server/src/utils/backups/cloud-storage.ts | 9 ++++----- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/dokploy/components/dashboard/database/backups/cloud-storage/show-cloud-backups.tsx b/apps/dokploy/components/dashboard/database/backups/cloud-storage/show-cloud-backups.tsx index 29c6be36..a039b9a4 100644 --- a/apps/dokploy/components/dashboard/database/backups/cloud-storage/show-cloud-backups.tsx +++ b/apps/dokploy/components/dashboard/database/backups/cloud-storage/show-cloud-backups.tsx @@ -210,7 +210,8 @@ export const ShowCloudBackups = ({ databaseId, databaseType }: Props) => { setActiveManualBackup(undefined); }} > - {isManualBackup && activeManualBackup === backup.id ? ( + {isManualBackup && + activeManualBackup === backup.id ? (
) : ( diff --git a/apps/dokploy/components/dashboard/settings/destination/cloud-storage-destinations.tsx b/apps/dokploy/components/dashboard/settings/destination/cloud-storage-destinations.tsx index 7a91a650..0b9fcd27 100644 --- a/apps/dokploy/components/dashboard/settings/destination/cloud-storage-destinations.tsx +++ b/apps/dokploy/components/dashboard/settings/destination/cloud-storage-destinations.tsx @@ -249,7 +249,7 @@ export const CloudStorageDestinations = ({ if (!result.token) { toast.success("Connection test successful"); } - } catch (err: any) { + } catch (_err: any) { setConnectionTested(false); form.setValue("token", ""); toast.error("Connection test failed", { diff --git a/apps/dokploy/server/api/routers/cloud-storage-backup.ts b/apps/dokploy/server/api/routers/cloud-storage-backup.ts index 40e91e55..91610356 100644 --- a/apps/dokploy/server/api/routers/cloud-storage-backup.ts +++ b/apps/dokploy/server/api/routers/cloud-storage-backup.ts @@ -100,6 +100,16 @@ async function withSilentTokenRefresh(params: { ) { console.log("Token expired or invalid, attempting refresh"); credentials.token = undefined; + // Update the config in database to reflect token removal + if (updateConfig) { + await db + .update(cloudStorageDestination) + .set({ + config: JSON.stringify(credentials), + updatedAt: new Date(), + }) + .where(eq(cloudStorageDestination.id, destination.id)); + } } else { throw err; } @@ -222,9 +232,9 @@ export const cloudStorageBackupRouter = createTRPCRouter({ console.log("Parsed files:", files); const backupFiles = files - .filter((file) => - file.Name.endsWith(".zip") || - file.Name.endsWith(".sql.gz") + .filter( + (file) => + file.Name.endsWith(".zip") || file.Name.endsWith(".sql.gz"), ) .map((file) => ({ path: file.Path, diff --git a/apps/dokploy/server/api/routers/cloud-storage-destination.ts b/apps/dokploy/server/api/routers/cloud-storage-destination.ts index 1445088e..470fadba 100644 --- a/apps/dokploy/server/api/routers/cloud-storage-destination.ts +++ b/apps/dokploy/server/api/routers/cloud-storage-destination.ts @@ -303,7 +303,7 @@ export const cloudStorageDestinationRouter = createTRPCRouter({ }); } }), - + // Delete a cloud storage destination delete: protectedProcedure .input(apiDeleteCloudStorageDestination) @@ -564,7 +564,7 @@ export const cloudStorageDestinationRouter = createTRPCRouter({ message: "Destination not found", }); } - + let credentials: any = {}; try { credentials = dest.config ? JSON.parse(dest.config) : {}; diff --git a/packages/server/src/utils/backups/cloud-storage.ts b/packages/server/src/utils/backups/cloud-storage.ts index d6e18081..6a7c8cfa 100644 --- a/packages/server/src/utils/backups/cloud-storage.ts +++ b/packages/server/src/utils/backups/cloud-storage.ts @@ -275,10 +275,10 @@ export const executeCloudStorageRestore = async ( emit("Downloading backup file..."); const credentials = await getCloudStorageCredentials(destination); - + // Get just the filename without any provider prefix - const cleanFileName = fileName.replace(/^[^:]+:/, ''); - + const cleanFileName = fileName.replace(/^[^:]+:/, ""); + // Construct the full path for the cloud storage provider const normalizedPrefix = normalizeCloudPath(backup.prefix || ""); const fullPath = `${destination.provider}:${normalizedPrefix}${cleanFileName}`; @@ -387,7 +387,7 @@ export const executeCloudStorageRestore = async ( } if (restoreCommand) { - emit(`Executing restore command...`); + emit("Executing restore command..."); await execAsync(restoreCommand); } @@ -499,4 +499,3 @@ export const keepLatestNCloudStorageBackups = async ( console.error("Error keeping latest backups:", error); } }; -