1
0
Fork 0
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:
Harry 2025-03-12 13:11:12 +08:00 committed by GitHub
parent bd70abce6e
commit d6c7d8a4f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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