mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 20:20:59 +08:00
Chore: General notification reformatting (#3182)
- I unified where in file the name of `NotificationProvider.name` is placed - I made sure that all the providers adhere to the signature of `NotificationProvider.send()` - I made sure that all the providers use `okMsg` if returning success messages directly from the function. Here a discussion should be had: Should this be refactored into a constant of `NotificationProvider`? I could imagine that `NotificationProvider.SENDING_SUCCESSFULL` could be a suitable alternative. - I made sure all providers have the URL they `POST`/`GET` to be extraced into a variable. => refactored this way due to Nelsons suggestion
This commit is contained in:
@@ -3,28 +3,23 @@ const axios = require("axios");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
|
||||
class LunaSea extends NotificationProvider {
|
||||
|
||||
name = "lunasea";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
let okMsg = "Sent Successfully.";
|
||||
let lunaseaurl = "";
|
||||
if (notification.lunaseaTarget === "user") {
|
||||
lunaseaurl = "https://notify.lunasea.app/v1/custom/user/" + notification.lunaseaUserID;
|
||||
} else {
|
||||
lunaseaurl = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
|
||||
}
|
||||
const okMsg = "Sent Successfully.";
|
||||
const url = "https://notify.lunasea.app/v1";
|
||||
|
||||
try {
|
||||
const target = this.getTarget(notification);
|
||||
if (heartbeatJSON == null) {
|
||||
let testdata = {
|
||||
"title": "Uptime Kuma Alert",
|
||||
"body": msg,
|
||||
};
|
||||
await axios.post(lunaseaurl, testdata);
|
||||
await axios.post(`${url}/custom/${target}`, testdata);
|
||||
return okMsg;
|
||||
}
|
||||
|
||||
@@ -35,7 +30,7 @@ class LunaSea extends NotificationProvider {
|
||||
heartbeatJSON["msg"] +
|
||||
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||
};
|
||||
await axios.post(lunaseaurl, downdata);
|
||||
await axios.post(`${url}/custom/${target}`, downdata);
|
||||
return okMsg;
|
||||
}
|
||||
|
||||
@@ -46,13 +41,25 @@ class LunaSea extends NotificationProvider {
|
||||
heartbeatJSON["msg"] +
|
||||
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||
};
|
||||
await axios.post(lunaseaurl, updata);
|
||||
await axios.post(`${url}/custom/${target}`, updata);
|
||||
return okMsg;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the lunasea target to send the notification to
|
||||
* @param {BeanModel} notification Notification details
|
||||
* @returns {string} The target to send the notification to
|
||||
*/
|
||||
getTarget(notification) {
|
||||
if (notification.lunaseaTarget === "user") {
|
||||
return "user/" + notification.lunaseaUserID;
|
||||
}
|
||||
return "device/" + notification.lunaseaDevice;
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user