This commit is contained in:
Théo LAGACHE
2026-01-07 15:00:11 +01:00
parent da3d4350cc
commit 585ee041ec
38 changed files with 128 additions and 216 deletions
@@ -66,10 +66,8 @@ export function backupColumns(
header: "Reference",
cell: ({row}) => {
const fileName = row.original.file
console.log(row.original)
const reference = row.original.id
const isImported = isImportedFilename(`${fileName}`)
console.log(isImported)
return isImported ? `${reference} (imported)` : `${reference}`
},
},
@@ -77,7 +75,6 @@ export function backupColumns(
accessorKey: "fileSize",
header: "Size",
cell: ({row}) => {
console.log(row.original.fileSize)
return formatBytes(row.getValue("fileSize"))
},
},
@@ -163,7 +160,6 @@ export function backupColumns(
} else if (settings.storage == "s3") {
data = await getFileUrlPreSignedS3Action(`backups/${database.project?.slug}/${fileName}`);
}
console.log(data)
if (data?.data?.success) {
url = data.data.value ?? "";
} else {
+1 -1
View File
@@ -84,7 +84,7 @@ export async function dispatchNotification(
success: false,
channelId: channelId || "",
provider: null,
error: "Channel not active¬",
error: "Channel not active",
};
}
+59 -62
View File
@@ -1,67 +1,64 @@
import {DatabaseWith} from "@/db/schema/07_database";
import {EventKind, EventPayload} from "@/features/notifications/types";
import {dispatchNotification} from "@/features/notifications/dispatch";
import { DatabaseWith } from "@/db/schema/07_database";
import { EventKind, EventPayload } from "@/features/notifications/types";
import { dispatchNotification } from "@/features/notifications/dispatch";
export async function sendNotificationsBackupRestore(database: DatabaseWith, event: EventKind) {
if (database.alertPolicies && database.alertPolicies.length > 0) {
for (const alertPolicy of database.alertPolicies) {
if (alertPolicy.enabled) {
const eventKinds = alertPolicy.eventKinds
if (eventKinds.includes(event)) {
const date = new Date()
let level: "info" | "critical" = "info";
let message = "";
let error: string | null = null;
switch (event) {
case "error_backup":
case "error_restore":
level = "critical";
message = `An error occurred during ${event.includes("backup") ? "backup" : "restore"} on ${date.toISOString()}.`;
error = "Check database connection or agent";
break;
case "success_backup":
case "success_restore":
level = "info";
message = `${event.includes("backup") ? "Backup" : "Restore"} completed successfully at ${date.toISOString()}.`;
break;
case "weekly_report":
level = "info";
message = `Weekly report generated at ${date.toISOString()}.`;
break;
}
const titleMap: Record<EventKind, string> = {
error_backup: `Backup Notification`,
error_restore: `Restore Notification`,
success_backup: `Backup Notification`,
success_restore: `Restore Notification`,
weekly_report: `Weekly Report Notification`,
};
const payload: EventPayload = {
title: titleMap[event],
message,
level: level,
event: event,
data: {
host: database.name,
id: database.id,
agentDatabaseId: database.agentDatabaseId,
error,
},
};
return await dispatchNotification(payload, alertPolicy.id, undefined, undefined);
}
}
}
if (!database.alertPolicies || database.alertPolicies.length === 0) {
return [];
}
const activePolicies = database.alertPolicies.filter(policy =>
policy.enabled && policy.eventKinds.includes(event)
);
const promises = activePolicies.map(alertPolicy => {
const date = new Date();
let level: "info" | "critical" = "info";
let message = "";
let error: string | null = null;
switch (event) {
case "error_backup":
case "error_restore":
level = "critical";
message = `An error occurred during ${event.includes("backup") ? "backup" : "restore"} on ${date.toISOString()}.`;
error = "Check database connection or agent";
break;
case "success_backup":
case "success_restore":
level = "info";
message = `${event.includes("backup") ? "Backup" : "Restore"} completed successfully at ${date.toISOString()}.`;
break;
case "weekly_report":
level = "info";
message = `Weekly report generated at ${date.toISOString()}.`;
break;
}
const titleMap: Record<EventKind, string> = {
error_backup: `Backup Notification`,
error_restore: `Restore Notification`,
success_backup: `Backup Notification`,
success_restore: `Restore Notification`,
weekly_report: `Weekly Report Notification`,
};
const payload: EventPayload = {
title: titleMap[event],
message,
level: level,
event: event,
data: {
host: database.name,
id: database.id,
agentDatabaseId: database.agentDatabaseId,
error,
},
};
return dispatchNotification(payload, alertPolicy.id, undefined, undefined);
});
return Promise.all(promises);
}
@@ -59,7 +59,6 @@ async function uploadLocal(fileName: string, buffer: any) {
await mkdir(path.join(process.cwd(), localDir), {recursive: true});
return await writeFile(path.join(process.cwd(), localDir + fileName), buffer);
} catch (error) {
console.log("Error occured ", error);
throw new Error("An error occured while importing image");
}
}