Skip to content

Commit e06f597

Browse files
author
Mauricio Siu
committed
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.
1 parent 6b346d3 commit e06f597

File tree

1 file changed

+9
-12
lines changed
  • packages/server/src/utils/notifications

1 file changed

+9
-12
lines changed

packages/server/src/utils/notifications/utils.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,17 @@ export const sendNtfyNotification = async (
156156
actions: string,
157157
message: string,
158158
) => {
159-
const headers: Record<string, string> = {
160-
"X-Priority": connection.priority?.toString() || "3",
161-
"X-Title": title,
162-
"X-Tags": tags,
163-
"X-Actions": actions,
164-
};
165-
166-
if (connection.accessToken) {
167-
headers.Authorization = `Bearer ${connection.accessToken}`;
168-
}
169-
170159
const response = await fetch(`${connection.serverUrl}/${connection.topic}`, {
171160
method: "POST",
172-
headers,
161+
headers: {
162+
...(connection.accessToken && {
163+
Authorization: `Bearer ${connection.accessToken}`,
164+
}),
165+
"X-Priority": connection.priority?.toString() || "3",
166+
"X-Title": title,
167+
"X-Tags": tags,
168+
"X-Actions": actions,
169+
},
173170
body: message,
174171
});
175172

0 commit comments

Comments
 (0)