refactor: streamline notification header construction in sendNtfyNotification

- Consolidated header creation for the notification request, improving code readability and maintainability.
- Made the Authorization header conditional based on the presence of accessToken, enhancing flexibility.
This commit is contained in:
Mauricio Siu
2025-12-01 00:46:35 -06:00
parent 6b346d30ee
commit e06f5979c3

View File

@@ -156,20 +156,17 @@ export const sendNtfyNotification = async (
actions: string,
message: string,
) => {
const headers: Record<string, string> = {
"X-Priority": connection.priority?.toString() || "3",
"X-Title": title,
"X-Tags": tags,
"X-Actions": actions,
};
if (connection.accessToken) {
headers.Authorization = `Bearer ${connection.accessToken}`;
}
const response = await fetch(`${connection.serverUrl}/${connection.topic}`, {
method: "POST",
headers,
headers: {
...(connection.accessToken && {
Authorization: `Bearer ${connection.accessToken}`,
}),
"X-Priority": connection.priority?.toString() || "3",
"X-Title": title,
"X-Tags": tags,
"X-Actions": actions,
},
body: message,
});