refactor: clean up cloud storage components

This commit is contained in:
vishalkadam47
2025-06-01 04:26:21 +05:30
parent 5c3e7ed87f
commit 02b25ce047
5 changed files with 22 additions and 12 deletions

View File

@@ -210,7 +210,8 @@ export const ShowCloudBackups = ({ databaseId, databaseType }: Props) => {
setActiveManualBackup(undefined); setActiveManualBackup(undefined);
}} }}
> >
{isManualBackup && activeManualBackup === backup.id ? ( {isManualBackup &&
activeManualBackup === backup.id ? (
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-primary" /> <div className="animate-spin rounded-full h-5 w-5 border-b-2 border-primary" />
) : ( ) : (
<Play className="size-5 text-muted-foreground" /> <Play className="size-5 text-muted-foreground" />

View File

@@ -249,7 +249,7 @@ export const CloudStorageDestinations = ({
if (!result.token) { if (!result.token) {
toast.success("Connection test successful"); toast.success("Connection test successful");
} }
} catch (err: any) { } catch (_err: any) {
setConnectionTested(false); setConnectionTested(false);
form.setValue("token", ""); form.setValue("token", "");
toast.error("Connection test failed", { toast.error("Connection test failed", {

View File

@@ -100,6 +100,16 @@ async function withSilentTokenRefresh(params: {
) { ) {
console.log("Token expired or invalid, attempting refresh"); console.log("Token expired or invalid, attempting refresh");
credentials.token = undefined; 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 { } else {
throw err; throw err;
} }
@@ -222,9 +232,9 @@ export const cloudStorageBackupRouter = createTRPCRouter({
console.log("Parsed files:", files); console.log("Parsed files:", files);
const backupFiles = files const backupFiles = files
.filter((file) => .filter(
file.Name.endsWith(".zip") || (file) =>
file.Name.endsWith(".sql.gz") file.Name.endsWith(".zip") || file.Name.endsWith(".sql.gz"),
) )
.map((file) => ({ .map((file) => ({
path: file.Path, path: file.Path,

View File

@@ -303,7 +303,7 @@ export const cloudStorageDestinationRouter = createTRPCRouter({
}); });
} }
}), }),
// Delete a cloud storage destination // Delete a cloud storage destination
delete: protectedProcedure delete: protectedProcedure
.input(apiDeleteCloudStorageDestination) .input(apiDeleteCloudStorageDestination)
@@ -564,7 +564,7 @@ export const cloudStorageDestinationRouter = createTRPCRouter({
message: "Destination not found", message: "Destination not found",
}); });
} }
let credentials: any = {}; let credentials: any = {};
try { try {
credentials = dest.config ? JSON.parse(dest.config) : {}; credentials = dest.config ? JSON.parse(dest.config) : {};

View File

@@ -275,10 +275,10 @@ export const executeCloudStorageRestore = async (
emit("Downloading backup file..."); emit("Downloading backup file...");
const credentials = await getCloudStorageCredentials(destination); const credentials = await getCloudStorageCredentials(destination);
// Get just the filename without any provider prefix // 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 // Construct the full path for the cloud storage provider
const normalizedPrefix = normalizeCloudPath(backup.prefix || ""); const normalizedPrefix = normalizeCloudPath(backup.prefix || "");
const fullPath = `${destination.provider}:${normalizedPrefix}${cleanFileName}`; const fullPath = `${destination.provider}:${normalizedPrefix}${cleanFileName}`;
@@ -387,7 +387,7 @@ export const executeCloudStorageRestore = async (
} }
if (restoreCommand) { if (restoreCommand) {
emit(`Executing restore command...`); emit("Executing restore command...");
await execAsync(restoreCommand); await execAsync(restoreCommand);
} }
@@ -499,4 +499,3 @@ export const keepLatestNCloudStorageBackups = async (
console.error("Error keeping latest backups:", error); console.error("Error keeping latest backups:", error);
} }
}; };