mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-14 12:11:01 +03:00
Update server/notification-providers/yzj.js
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
parent
bd70abce6e
commit
d6c7d8a4f5
1 changed files with 12 additions and 28 deletions
|
@ -12,46 +12,30 @@ class YZJ extends NotificationProvider {
|
|||
let okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
|
||||
if (heartbeatJSON != null) {
|
||||
if (heartbeatJSON !== null) {
|
||||
msg = `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
||||
}
|
||||
|
||||
let params = {
|
||||
const config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
content: msg
|
||||
};
|
||||
const url = `${notification.yzjWebHookUrl}?yzjtype=${notification.yzjType}&yzjtoken=${notification.yzjToken}`;
|
||||
|
||||
if (await this.sendToYZJ(notification, params)) {
|
||||
return okMsg;
|
||||
const result = await axios.post(url, params, config);
|
||||
if (!result.data?.success) {
|
||||
throw new Error(result.data?.errmsg ?? "yzj's server did not respond with the expected result");
|
||||
}
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to YZJ
|
||||
* @param {object} notification Notification
|
||||
* @param {object} params Parameters of message
|
||||
* @returns {boolean} True if successful else false
|
||||
*/
|
||||
async sendToYZJ(notification, params) {
|
||||
|
||||
let config = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
url: `${notification.yzjWebHookUrl}?yzjtype=${notification.yzjType}&yzjtoken=${notification.yzjToken}`,
|
||||
data: JSON.stringify(params),
|
||||
};
|
||||
|
||||
let result = await axios(config);
|
||||
if (!result.data?.success) {
|
||||
throw new Error(result.data?.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert status constant to string
|
||||
* @param {string} status The status constant
|
||||
|
|
Loading…
Add table
Reference in a new issue