From e06f5979c30fe43e6b99f347b55353ae921c6c5d Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Mon, 1 Dec 2025 00:46:35 -0600 Subject: [PATCH] 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. --- .../server/src/utils/notifications/utils.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/server/src/utils/notifications/utils.ts b/packages/server/src/utils/notifications/utils.ts index b0d956470..328df0b87 100644 --- a/packages/server/src/utils/notifications/utils.ts +++ b/packages/server/src/utils/notifications/utils.ts @@ -156,20 +156,17 @@ export const sendNtfyNotification = async ( actions: string, message: string, ) => { - const headers: Record = { - "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, });