From c1ad9c749489035e74d170a8daf3f8c53fcbea51 Mon Sep 17 00:00:00 2001 From: chiko Date: Sun, 26 Oct 2025 14:08:10 +0100 Subject: [PATCH] Added env vars to function sendNotification --- src/sendNotification.ts | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/sendNotification.ts b/src/sendNotification.ts index 3f541be..88746c5 100644 --- a/src/sendNotification.ts +++ b/src/sendNotification.ts @@ -6,21 +6,28 @@ export async function sendNotification(title: string, body: string, link?: strin link } }); - const response = await fetch("http://apprise:8000/notify", { - method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify({ - urls: [ - `ntfys://${process.env.ntfy_username}:${process.env.ntfy_password}@${process.env.ntfy_host}/${process.env.ntfy_topic}${ link ? `?click=${link}`: "?click=https://77th-jsoc.com/#/events" }`, - `discord://${process.env.dc_webhook}?avatar_url=${process.env.dc_avatar_url}&botname=${process.env.dc_botname}` - ].join(","), - title: title, - body: body, - format: "markdown" + if ( ! ( process.env.notification_mock == "true" ) ) { + const response = await fetch(`${ process.env.apprise_https == "true" ? "https" : "http"}://${process.env.apprise_host ? process.env.apprise_host : "apprise"}:${process.env.apprise_port ? String(process.env.apprise_port) : "80" }/notify"`, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + urls: [ + `ntfys://${process.env.ntfy_username}:${process.env.ntfy_password}@${process.env.ntfy_host}/${process.env.ntfy_topic}${ link ? `?click=${link}`: "?click=https://77th-jsoc.com/#/events" }`, + `discord://${process.env.dc_webhook}?avatar_url=${process.env.dc_avatar_url}&botname=${process.env.dc_botname}` + ].join(","), + title: title, + body: body, + format: "markdown" + }) + }); + const responseBody = await response.json(); + return responseBody; + } else { + console.dir({ + sendNotification: "mocking" }) - }); - const responseBody = await response.json(); - return responseBody; -} \ No newline at end of file + } + +} \ No newline at end of file