mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
Feat/notifications alerts (#52)
* feat: notifications backend & creation * feat: assign notification to backup schedule * refactor: status dot one component * chore(notification-details): remove refetchInterval
This commit is contained in:
43
app/server/utils/shoutrrr.ts
Normal file
43
app/server/utils/shoutrrr.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { safeSpawn } from "./spawn";
|
||||
import { logger } from "./logger";
|
||||
import { toMessage } from "./errors";
|
||||
|
||||
export interface SendNotificationParams {
|
||||
shoutrrrUrl: string;
|
||||
title: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export async function sendNotification(params: SendNotificationParams) {
|
||||
const { shoutrrrUrl, title, body } = params;
|
||||
|
||||
try {
|
||||
const args = ["send", "--url", shoutrrrUrl, "--title", title, "--message", body];
|
||||
|
||||
logger.debug(`Sending notification via Shoutrrr: ${title}`);
|
||||
|
||||
const result = await safeSpawn({
|
||||
command: "shoutrrr",
|
||||
args,
|
||||
});
|
||||
|
||||
if (result.exitCode === 0) {
|
||||
logger.debug(`Notification sent successfully: ${title}`);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
const errorMessage = result.stderr || result.stdout || "Unknown error";
|
||||
logger.error(`Failed to send notification: ${errorMessage}`);
|
||||
return {
|
||||
success: false,
|
||||
error: errorMessage,
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = toMessage(error);
|
||||
logger.error(`Error sending notification: ${errorMessage}`);
|
||||
return {
|
||||
success: false,
|
||||
error: errorMessage,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user