Fix previously PR bug about Bark Notification (#2084)

Co-authored-by: zuosc <zorro.zsc@hotmail.com>
This commit is contained in:
Super Manito 2022-09-16 14:21:22 +08:00 committed by GitHub
parent e815e51608
commit 38c45a3fe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,17 +28,17 @@ class Bark extends NotificationProvider {
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) { if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
let title = "UptimeKuma Monitor Up"; let title = "UptimeKuma Monitor Up";
return await this.postNotification(title, msg, barkEndpoint); return await this.postNotification(notification, title, msg, barkEndpoint);
} }
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) { if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
let title = "UptimeKuma Monitor Down"; let title = "UptimeKuma Monitor Down";
return await this.postNotification(title, msg, barkEndpoint); return await this.postNotification(notification, title, msg, barkEndpoint);
} }
if (msg != null) { if (msg != null) {
let title = "UptimeKuma Message"; let title = "UptimeKuma Message";
return await this.postNotification(title, msg, barkEndpoint); return await this.postNotification(notification, title, msg, barkEndpoint);
} }
} }
@ -50,7 +50,7 @@ class Bark extends NotificationProvider {
*/ */
appendAdditionalParameters(notification, postUrl) { appendAdditionalParameters(notification, postUrl) {
// set icon to uptime kuma icon, 11kb should be fine // set icon to uptime kuma icon, 11kb should be fine
postUrl += "&icon=" + barkNotificationAvatar; postUrl += "?icon=" + barkNotificationAvatar;
// grouping all our notifications // grouping all our notifications
if (notification.barkGroup != null) { if (notification.barkGroup != null) {
postUrl += "&group=" + notification.barkGroup; postUrl += "&group=" + notification.barkGroup;
@ -89,12 +89,12 @@ class Bark extends NotificationProvider {
* @param {string} endpoint Endpoint to send request to * @param {string} endpoint Endpoint to send request to
* @returns {string} * @returns {string}
*/ */
async postNotification(title, subtitle, endpoint) { async postNotification(notification, title, subtitle, endpoint) {
// url encode title and subtitle // url encode title and subtitle
title = encodeURIComponent(title); title = encodeURIComponent(title);
subtitle = encodeURIComponent(subtitle); subtitle = encodeURIComponent(subtitle);
let postUrl = endpoint + "/" + title + "/" + subtitle; let postUrl = endpoint + "/" + title + "/" + subtitle;
postUrl = this.appendAdditionalParameters(postUrl); postUrl = this.appendAdditionalParameters(notification, postUrl);
let result = await axios.get(postUrl); let result = await axios.get(postUrl);
this.checkResult(result); this.checkResult(result);
if (result.statusText != null) { if (result.statusText != null) {