mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-20 21:24:44 -05:00
Use API v2 for Bark notification (#2759)
* Use API v2 for Bark notification * API v2 endpoint should end with path `/push` * Support both v1 and v2 * Flip the bool * Allow selecting api version * Apply review suggestion Co-authored-by: Nelson Chan <3271800+chakflying@users.noreply.github.com> * Add translated string to `en.json` * Apply review suggestion Co-authored-by: Nelson Chan <3271800+chakflying@users.noreply.github.com> --------- Co-authored-by: Nelson Chan <3271800+chakflying@users.noreply.github.com>
This commit is contained in:
parent
de7bc487ed
commit
499429858c
@ -46,8 +46,7 @@ class Bark extends NotificationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add additional parameter for better on device styles (iOS 15
|
* Add additional parameter for Bark v1 endpoints
|
||||||
* optimized)
|
|
||||||
* @param {BeanModel} notification Notification to send
|
* @param {BeanModel} notification Notification to send
|
||||||
* @param {string} postUrl URL to append parameters to
|
* @param {string} postUrl URL to append parameters to
|
||||||
* @returns {string} Additional URL parameters
|
* @returns {string} Additional URL parameters
|
||||||
@ -96,12 +95,23 @@ class Bark extends NotificationProvider {
|
|||||||
* @returns {string} Success message
|
* @returns {string} Success message
|
||||||
*/
|
*/
|
||||||
async postNotification(notification, title, subtitle, endpoint) {
|
async postNotification(notification, title, subtitle, endpoint) {
|
||||||
// url encode title and subtitle
|
let result;
|
||||||
title = encodeURIComponent(title);
|
if (notification.apiVersion === "v1" || notification.apiVersion == null) {
|
||||||
subtitle = encodeURIComponent(subtitle);
|
// url encode title and subtitle
|
||||||
let postUrl = endpoint + "/" + title + "/" + subtitle;
|
title = encodeURIComponent(title);
|
||||||
postUrl = this.appendAdditionalParameters(notification, postUrl);
|
subtitle = encodeURIComponent(subtitle);
|
||||||
let result = await axios.get(postUrl);
|
let postUrl = endpoint + "/" + title + "/" + subtitle;
|
||||||
|
postUrl = this.appendAdditionalParameters(notification, postUrl);
|
||||||
|
result = await axios.get(postUrl);
|
||||||
|
} else {
|
||||||
|
result = await axios.post(`${endpoint}/push`, {
|
||||||
|
title,
|
||||||
|
body: subtitle,
|
||||||
|
icon: barkNotificationAvatar,
|
||||||
|
sound: notification.barkSound || "telegraph", // default sound is telegraph
|
||||||
|
group: notification.barkGroup || "UptimeKuma", // default group is UptimeKuma
|
||||||
|
});
|
||||||
|
}
|
||||||
this.checkResult(result);
|
this.checkResult(result);
|
||||||
if (result.statusText != null) {
|
if (result.statusText != null) {
|
||||||
return "Bark notification succeed: " + result.statusText;
|
return "Bark notification succeed: " + result.statusText;
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="Bark API Version" class="form-label">{{ $t("Bark API Version") }}</label>
|
||||||
|
<select id="Bark API Version" v-model="$parent.notification.apiVersion" class="form-select" required>
|
||||||
|
<option value="v1">v1</option>
|
||||||
|
<option value="v2">v2</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="Bark Endpoint" class="form-label">{{ $t("Bark Endpoint") }}<span style="color: red;"><sup>*</sup></span></label>
|
<label for="Bark Endpoint" class="form-label">{{ $t("Bark Endpoint") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
<input id="Bark Endpoint" v-model="$parent.notification.barkEndpoint" type="text" class="form-control" required>
|
<input id="Bark Endpoint" v-model="$parent.notification.barkEndpoint" type="text" class="form-control" required>
|
||||||
|
@ -626,6 +626,7 @@
|
|||||||
"TemplateCode": "TemplateCode",
|
"TemplateCode": "TemplateCode",
|
||||||
"SignName": "SignName",
|
"SignName": "SignName",
|
||||||
"Sms template must contain parameters: ": "Sms template must contain parameters: ",
|
"Sms template must contain parameters: ": "Sms template must contain parameters: ",
|
||||||
|
"Bark API Version": "Bark API Version",
|
||||||
"Bark Endpoint": "Bark Endpoint",
|
"Bark Endpoint": "Bark Endpoint",
|
||||||
"Bark Group": "Bark Group",
|
"Bark Group": "Bark Group",
|
||||||
"Bark Sound": "Bark Sound",
|
"Bark Sound": "Bark Sound",
|
||||||
|
Loading…
Reference in New Issue
Block a user