fix: added support for Basic Auth ntfy instance

This commit is contained in:
charlesgauthereau
2026-01-24 19:04:49 +01:00
parent 228ff75468
commit 727d9eb57c
2 changed files with 40 additions and 3 deletions
+7 -2
View File
@@ -1,10 +1,10 @@
import type {EventPayload, DispatchResult} from '../types';
export async function sendNtfy(
config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string },
config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string, ntfyUsername?: string, ntfyPassword?: string },
payload: EventPayload
): Promise<DispatchResult> {
const {ntfyServerUrl, ntfyTopic, ntfyToken} = config;
const {ntfyServerUrl, ntfyTopic, ntfyToken, ntfyUsername, ntfyPassword} = config;
const baseUrl = (ntfyServerUrl || "https://ntfy.sh").replace(/\/$/, "");
@@ -24,6 +24,11 @@ export async function sendNtfy(
headers['Authorization'] = `Bearer ${ntfyToken}`;
}
if (ntfyUsername && ntfyPassword) {
const credentials = btoa(`${ntfyUsername}:${ntfyPassword}`);
headers['Authorization'] = `Basic ${credentials}`;
}
const res = await fetch(`${baseUrl}`, {
method: 'POST',
body: JSON.stringify(body),