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);
}}
>
{isManualBackup && activeManualBackup === backup.id ? (
{isManualBackup &&
activeManualBackup === backup.id ? (
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-primary" />
) : (
<Play className="size-5 text-muted-foreground" />

View File

@@ -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", {

View File

@@ -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,

View File

@@ -277,7 +277,7 @@ export const executeCloudStorageRestore = async (
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 || "");
@@ -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);
}
};