mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-14 16:42:35 +02:00
Fix to avoid checking same monitor
* Refactor verification of matching properties
This commit is contained in:
parent
5b453e9e2a
commit
7d347929a5
1 changed files with 10 additions and 6 deletions
|
@ -561,12 +561,9 @@ exports.entryPage = "dashboard";
|
||||||
try {
|
try {
|
||||||
let monitorList = await sendMonitorList(socket);
|
let monitorList = await sendMonitorList(socket);
|
||||||
for (let monitorId in monitorList) {
|
for (let monitorId in monitorList) {
|
||||||
if (monitorList[monitorId].name === monitor.name) {
|
let monitorFromList = monitorList[monitorId];
|
||||||
throw new Error("duplicatedMonitorNameWarning");
|
verifyPropertyAndThrowIfMatch(monitorFromList, monitor, "name");
|
||||||
}
|
verifyPropertyAndThrowIfMatch(monitorFromList, monitor, "url");
|
||||||
if (monitorList[monitorId].url === monitor.url) {
|
|
||||||
throw new Error("duplicatedMonitorUrlWarning");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
|
@ -1548,6 +1545,13 @@ async function shutdownFunction(signal) {
|
||||||
await Database.close();
|
await Database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function verifyPropertyAndThrowIfMatch(monitorFromList, incomingMonitor, property) {
|
||||||
|
let capitalizedProperty = property.charAt(0).toUpperCase() + property.slice(1);
|
||||||
|
if (monitorFromList.id !== incomingMonitor.id && monitorFromList[property] === incomingMonitor[property]) {
|
||||||
|
throw new Error(`duplicatedMonitor${capitalizedProperty}Warning`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function finalFunction() {
|
function finalFunction() {
|
||||||
console.log("Graceful shutdown successful!");
|
console.log("Graceful shutdown successful!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue