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
@@ -3,7 +3,6 @@ import {FormControl, FormField, FormItem, FormLabel, FormMessage} from "@/compon
import {Input} from "@/components/ui/input"; import {Input} from "@/components/ui/input";
import {Separator} from "@/components/ui/separator"; import {Separator} from "@/components/ui/separator";
type NotifierNtfyFormProps = { type NotifierNtfyFormProps = {
form: UseFormReturn<any, any, any> form: UseFormReturn<any, any, any>
} }
@@ -12,6 +11,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
return ( return (
<> <>
<Separator className="my-1"/> <Separator className="my-1"/>
<FormField <FormField
control={form.control} control={form.control}
name="config.ntfyTopic" name="config.ntfyTopic"
@@ -25,6 +25,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
</FormItem> </FormItem>
)} )}
/> />
<FormField <FormField
control={form.control} control={form.control}
name="config.ntfyServerUrl" name="config.ntfyServerUrl"
@@ -39,6 +40,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
</FormItem> </FormItem>
)} )}
/> />
<FormField <FormField
control={form.control} control={form.control}
name="config.ntfyToken" name="config.ntfyToken"
@@ -53,6 +55,36 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
</FormItem> </FormItem>
)} )}
/> />
<Separator className="my-1"/>
<FormField
control={form.control}
name="config.ntfyUsername"
render={({field}) => (
<FormItem>
<FormLabel>Basic Auth Username (Optional)</FormLabel>
<FormControl>
<Input {...field} placeholder="username"/>
</FormControl>
<FormMessage/>
</FormItem>
)}
/>
<FormField
control={form.control}
name="config.ntfyPassword"
render={({field}) => (
<FormItem>
<FormLabel>Basic Auth Password (Optional)</FormLabel>
<FormControl>
<Input {...field} type="password" placeholder="password"/>
</FormControl>
<FormMessage/>
</FormItem>
)}
/>
</> </>
) )
} }
+7 -2
View File
@@ -1,10 +1,10 @@
import type {EventPayload, DispatchResult} from '../types'; import type {EventPayload, DispatchResult} from '../types';
export async function sendNtfy( export async function sendNtfy(
config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string }, config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string, ntfyUsername?: string, ntfyPassword?: string },
payload: EventPayload payload: EventPayload
): Promise<DispatchResult> { ): Promise<DispatchResult> {
const {ntfyServerUrl, ntfyTopic, ntfyToken} = config; const {ntfyServerUrl, ntfyTopic, ntfyToken, ntfyUsername, ntfyPassword} = config;
const baseUrl = (ntfyServerUrl || "https://ntfy.sh").replace(/\/$/, ""); const baseUrl = (ntfyServerUrl || "https://ntfy.sh").replace(/\/$/, "");
@@ -24,6 +24,11 @@ export async function sendNtfy(
headers['Authorization'] = `Bearer ${ntfyToken}`; headers['Authorization'] = `Bearer ${ntfyToken}`;
} }
if (ntfyUsername && ntfyPassword) {
const credentials = btoa(`${ntfyUsername}:${ntfyPassword}`);
headers['Authorization'] = `Basic ${credentials}`;
}
const res = await fetch(`${baseUrl}`, { const res = await fetch(`${baseUrl}`, {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),