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 {
|
||||
let monitorList = await sendMonitorList(socket);
|
||||
for (let monitorId in monitorList) {
|
||||
if (monitorList[monitorId].name === monitor.name) {
|
||||
throw new Error("duplicatedMonitorNameWarning");
|
||||
}
|
||||
if (monitorList[monitorId].url === monitor.url) {
|
||||
throw new Error("duplicatedMonitorUrlWarning");
|
||||
}
|
||||
let monitorFromList = monitorList[monitorId];
|
||||
verifyPropertyAndThrowIfMatch(monitorFromList, monitor, "name");
|
||||
verifyPropertyAndThrowIfMatch(monitorFromList, monitor, "url");
|
||||
}
|
||||
callback({
|
||||
ok: true,
|
||||
|
@ -1548,6 +1545,13 @@ async function shutdownFunction(signal) {
|
|||
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() {
|
||||
console.log("Graceful shutdown successful!");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue