mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-24 05:04:08 -08:00
Slightly refactor
This commit is contained in:
parent
792f3c7c5c
commit
30d8aadf12
|
@ -1,5 +1,6 @@
|
|||
const nodemailer = require("nodemailer");
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
|
||||
class SMTP extends NotificationProvider {
|
||||
|
||||
|
@ -34,27 +35,23 @@ class SMTP extends NotificationProvider {
|
|||
let replaceHostname = new RegExp("{HOSTNAME}", "g");
|
||||
let replaceStatus = new RegExp("{STATUS}", "g");
|
||||
|
||||
let serviceStatus;
|
||||
// Lets start with dummy values to simplify code
|
||||
let monitorName = "Test"
|
||||
let monitorHostname = "example.com"
|
||||
let serviceStatus = "⚠️ Test";
|
||||
|
||||
if (monitorJSON !== null) {
|
||||
customsubject = customsubject.replace(replaceName,monitorJSON["name"]);
|
||||
customsubject = customsubject.replace(replaceHostname,monitorJSON["hostname"]);
|
||||
} else {
|
||||
// Insert dummy values during test
|
||||
customsubject = customsubject.replace(replaceName,"Test");
|
||||
customsubject = customsubject.replace(replaceHostname,"example.com");
|
||||
monitorName = monitorJSON["name"];
|
||||
monitorHostname = monitorJSON["hostname"];
|
||||
}
|
||||
|
||||
if (heartbeatJSON !== null) {
|
||||
if (heartbeatJSON["status"] === 0) {
|
||||
serviceStatus = "🔴 Down"
|
||||
} else {
|
||||
serviceStatus = "✅ Up"
|
||||
serviceStatus = heartbeatJSON["status"] == DOWN ? "🔴 Down":"✅ Up";
|
||||
}
|
||||
// Break replace to one by line for better readability
|
||||
customsubject = customsubject.replace(replaceStatus,serviceStatus);
|
||||
} else {
|
||||
// Insert dummy values during test
|
||||
customsubject = customsubject.replace(replaceStatus,"TEST");
|
||||
}
|
||||
customsubject = customsubject.replace(replaceName,monitorName);
|
||||
customsubject = customsubject.replace(replaceHostname,monitorHostname);
|
||||
|
||||
subject = customsubject
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue