Skip to content

Commit 0e7ebb7

Browse files
authored
Merge pull request #42 from Portabase/fix/ntfy
fix: added support for Basic Auth ntfy instance
2 parents 228ff75 + 727d9eb commit 0e7ebb7

File tree

2 files changed

+40
-3
lines changed
  • src
    • components/wrappers/dashboard/admin/channels/channel/channel-form/providers/notifications/forms
    • features/notifications/providers

2 files changed

+40
-3
lines changed

src/components/wrappers/dashboard/admin/channels/channel/channel-form/providers/notifications/forms/ntfy.form.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {FormControl, FormField, FormItem, FormLabel, FormMessage} from "@/compon
33
import {Input} from "@/components/ui/input";
44
import {Separator} from "@/components/ui/separator";
55

6-
76
type NotifierNtfyFormProps = {
87
form: UseFormReturn<any, any, any>
98
}
@@ -12,6 +11,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
1211
return (
1312
<>
1413
<Separator className="my-1"/>
14+
1515
<FormField
1616
control={form.control}
1717
name="config.ntfyTopic"
@@ -25,6 +25,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
2525
</FormItem>
2626
)}
2727
/>
28+
2829
<FormField
2930
control={form.control}
3031
name="config.ntfyServerUrl"
@@ -39,6 +40,7 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
3940
</FormItem>
4041
)}
4142
/>
43+
4244
<FormField
4345
control={form.control}
4446
name="config.ntfyToken"
@@ -53,6 +55,36 @@ export const NotifierNtfyForm = ({form}: NotifierNtfyFormProps) => {
5355
</FormItem>
5456
)}
5557
/>
58+
59+
<Separator className="my-1"/>
60+
61+
<FormField
62+
control={form.control}
63+
name="config.ntfyUsername"
64+
render={({field}) => (
65+
<FormItem>
66+
<FormLabel>Basic Auth Username (Optional)</FormLabel>
67+
<FormControl>
68+
<Input {...field} placeholder="username"/>
69+
</FormControl>
70+
<FormMessage/>
71+
</FormItem>
72+
)}
73+
/>
74+
75+
<FormField
76+
control={form.control}
77+
name="config.ntfyPassword"
78+
render={({field}) => (
79+
<FormItem>
80+
<FormLabel>Basic Auth Password (Optional)</FormLabel>
81+
<FormControl>
82+
<Input {...field} type="password" placeholder="password"/>
83+
</FormControl>
84+
<FormMessage/>
85+
</FormItem>
86+
)}
87+
/>
5688
</>
5789
)
5890
}

src/features/notifications/providers/ntfy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type {EventPayload, DispatchResult} from '../types';
22

33
export async function sendNtfy(
4-
config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string },
4+
config: { ntfyServerUrl?: string; ntfyTopic: string; ntfyToken?: string, ntfyUsername?: string, ntfyPassword?: string },
55
payload: EventPayload
66
): Promise<DispatchResult> {
7-
const {ntfyServerUrl, ntfyTopic, ntfyToken} = config;
7+
const {ntfyServerUrl, ntfyTopic, ntfyToken, ntfyUsername, ntfyPassword} = config;
88

99
const baseUrl = (ntfyServerUrl || "https://ntfy.sh").replace(/\/$/, "");
1010

@@ -24,6 +24,11 @@ export async function sendNtfy(
2424
headers['Authorization'] = `Bearer ${ntfyToken}`;
2525
}
2626

27+
if (ntfyUsername && ntfyPassword) {
28+
const credentials = btoa(`${ntfyUsername}:${ntfyPassword}`);
29+
headers['Authorization'] = `Basic ${credentials}`;
30+
}
31+
2732
const res = await fetch(`${baseUrl}`, {
2833
method: 'POST',
2934
body: JSON.stringify(body),

0 commit comments

Comments
 (0)