From be9de5776f75db90fffc5ca6e8e9c5d8500c8725 Mon Sep 17 00:00:00 2001 From: MIt_gancm <72749591+MIt-gancm@users.noreply.github.com> Date: Sat, 9 Aug 2025 17:59:59 +0800 Subject: [PATCH] Update notify.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删多了刚刚 --- sample/notify.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sample/notify.js b/sample/notify.js index 04da4df2..815c419d 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -1282,6 +1282,35 @@ function webhookNotify(text, desp) { }); } + +function ntfyNotify(text, desp) { + function encodeRFC2047(text) { + const encodedBase64 = Buffer.from(text).toString('base64'); + return `=?utf-8?B?${encodedBase64}?=`; + } + + return new Promise((resolve) => { + const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD, NTFY_ACTIONS } = push_config; + if (NTFY_TOPIC) { + const options = { + url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`, + body: `${desp}`, + headers: { + Title: `${encodeRFC2047(text)}`, + Priority: NTFY_PRIORITY || '3', + Icon: 'https://qn.whyour.cn/logo.png', + }, + timeout, + }; + if (NTFY_TOKEN) { + options.headers['Authorization'] = `Bearer ${NTFY_TOKEN}`; + } else if (NTFY_USERNAME && NTFY_PASSWORD) { + options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`; + } + if (NTFY_ACTIONS) { + options.headers['Actions'] = encodeRFC2047(NTFY_ACTIONS); + } + $.post(options, (err, resp, data) => { try { if (err) {