Skip to content

Commit 3b57350

Browse files
committed
Updates regex for discord url and fixes auto not working
1 parent 2069130 commit 3b57350

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

server/database/queries/heartbeat.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ export const isMonitorDown = async (monitorId, limit = 1) => {
4343
const limitHeartbeats = heartbeats.slice(0, newLimit);
4444
const allDown = limitHeartbeats.every((heartbeat) => heartbeat.isDown);
4545

46-
if (oldestHeartbeat.isDown && allDown) {
46+
if (!oldestHeartbeat) {
47+
return false;
48+
}
49+
50+
if (oldestHeartbeat?.isDown && allDown) {
4751
return false;
4852
}
4953

5054
if (
5155
limitHeartbeats.every((heartbeat) => heartbeat.isDown) &&
52-
!oldestHeartbeat.isDown
56+
!oldestHeartbeat?.isDown
5357
) {
5458
return limitHeartbeats[0];
5559
}

server/middleware/monitor/add.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { cleanMonitor } from '../../class/monitor/index.js';
77
import { createMonitor } from '../../database/queries/monitor.js';
88
import { fetchHeartbeats } from '../../database/queries/heartbeat.js';
99
import { fetchCertificate } from '../../database/queries/certificate.js';
10+
import statusCache from '../../cache/status.js';
1011

1112
const stringifyJson = (obj, asArray = false) => {
1213
try {
@@ -146,6 +147,12 @@ const monitorAdd = async (request, response) => {
146147
cert,
147148
});
148149

150+
console.log(`Adding monitor ${monitor.monitorId} to status cache`);
151+
152+
await statusCache
153+
.loadMonitorData(monitor.monitorId)
154+
.catch((error) => console.log(error));
155+
149156
return response.json(monitor);
150157
} catch (error) {
151158
return handleError(error, response);

server/utils/status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const layoutCheck = (layout) => {
22
return (
33
(layout.type === 'metrics' && layout.autoAdd) ||
4-
(layout.type === 'uptime' && layout.graphType !== 'Basic' && layout.autoAdd)
4+
(layout.type === 'uptime' && layout.autoAdd)
55
);
66
};
77

shared/validators/notifications/discord.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NotificationValidatorError } from '../../utils/errors.js';
88
const friendlyNameRegex = /^[a-zA-Z0-9_-]+$/;
99
const messageTypes = ['basic', 'pretty', 'nerdy'];
1010
const tokenRegex =
11-
/^https:\/\/(?:discord\.com|discordapp\.com)\/api\/webhooks\/[0-9]+\/[0-9a-zA-Z_.-]+$/;
11+
/^https:\/\/(?:discord\.com|discordapp\.com)\/api\/webhooks\/[0-9]+\/[0-9a-zA-Z_.-]+(\?thread_id=[0-9]+)?$/;
1212
const usernameRegex = /^[a-zA-Z0-9_]{1,32}$/;
1313

1414
const Discord = ({

0 commit comments

Comments
 (0)