chore: enable formatting over the entire codebase in CI (#6655)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Frank Elsinga
2026-01-09 02:10:36 +01:00
committed by GitHub
co-authored by autofix-ci[bot]
parent 6658f2ce41
commit 0f61d7ee1b
422 changed files with 30897 additions and 27377 deletions
+45 -47
View File
@@ -28,7 +28,7 @@ let io = server.io;
router.get("/api/entry-page", async (request, response) => {
allowDevAllOrigin(response);
let result = { };
let result = {};
let hostname = request.hostname;
if ((await setting("trustProxy")) && request.headers["x-forwarded-host"]) {
hostname = request.headers["x-forwarded-host"];
@@ -50,13 +50,11 @@ router.all("/api/push/:pushToken", async (request, response) => {
let msg = request.query.msg || "OK";
let ping = parseFloat(request.query.ping) || null;
let statusString = request.query.status || "up";
const statusFromParam = (statusString === "up") ? UP : DOWN;
const statusFromParam = statusString === "up" ? UP : DOWN;
let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [
pushToken
]);
let monitor = await R.findOne("monitor", " push_token = ? AND active = 1 ", [pushToken]);
if (! monitor) {
if (!monitor) {
throw new Error("Monitor not found or not active.");
}
@@ -105,7 +103,10 @@ router.all("/api/push/:pushToken", async (request, response) => {
++bean.downCount;
if (bean.downCount >= monitor.resendInterval) {
// Send notification again, because we are still DOWN
log.debug("monitor", `[${monitor.name}] sendNotification again: Down Count: ${bean.downCount} | Resend Interval: ${monitor.resendInterval}`);
log.debug(
"monitor",
`[${monitor.name}] sendNotification again: Down Count: ${bean.downCount} | Resend Interval: ${monitor.resendInterval}`
);
await Monitor.sendNotification(isFirstBeat, monitor, bean);
// Reset down count
@@ -132,7 +133,7 @@ router.all("/api/push/:pushToken", async (request, response) => {
} catch (e) {
response.status(404).json({
ok: false,
msg: e.message
msg: e.message,
});
}
});
@@ -158,13 +159,14 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
const requestedMonitorId = parseInt(request.params.id, 10);
const overrideValue = value !== undefined ? parseInt(value) : undefined;
let publicMonitor = await R.getRow(`
let publicMonitor = await R.getRow(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND monitor_group.monitor_id = ?
AND public = 1
`,
[ requestedMonitorId ]
[requestedMonitorId]
);
const badgeValues = { style };
@@ -241,13 +243,14 @@ router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (reques
requestedDuration = `${requestedDuration}h`;
}
let publicMonitor = await R.getRow(`
let publicMonitor = await R.getRow(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND monitor_group.monitor_id = ?
AND public = 1
`,
[ requestedMonitorId ]
[requestedMonitorId]
);
const badgeValues = { style };
@@ -272,7 +275,7 @@ router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (reques
labelPrefix,
label ?? `Uptime (${requestedDuration.slice(0, -1)}${labelSuffix})`,
]);
badgeValues.message = filterAndJoin([ prefix, cleanUptime, suffix ]);
badgeValues.message = filterAndJoin([prefix, cleanUptime, suffix]);
}
// build the SVG based on given values
@@ -330,8 +333,11 @@ router.get("/api/badge/:id/ping/:duration?", cache("5 minutes"), async (request,
// use a given, custom labelColor or use the default badge label color (defined by badge-maker)
badgeValues.labelColor = labelColor ?? "";
// build a lable string. If a custom label is given, override the default one (requestedDuration)
badgeValues.label = filterAndJoin([ labelPrefix, label ?? `Avg. Ping (${requestedDuration.slice(0, -1)}${labelSuffix})` ]);
badgeValues.message = filterAndJoin([ prefix, avgPing, suffix ]);
badgeValues.label = filterAndJoin([
labelPrefix,
label ?? `Avg. Ping (${requestedDuration.slice(0, -1)}${labelSuffix})`,
]);
badgeValues.message = filterAndJoin([prefix, avgPing, suffix]);
}
// build the SVG based on given values
@@ -363,17 +369,14 @@ router.get("/api/badge/:id/avg-response/:duration?", cache("5 minutes"), async (
const requestedMonitorId = parseInt(request.params.id, 10);
// Default duration is 24 (h) if not defined in queryParam, limited to 720h (30d)
const requestedDuration = Math.min(
request.params.duration
? parseInt(request.params.duration, 10)
: 24,
720
);
const requestedDuration = Math.min(request.params.duration ? parseInt(request.params.duration, 10) : 24, 720);
const overrideValue = value && parseFloat(value);
const sqlHourOffset = Database.sqlHourOffset();
const publicAvgPing = parseInt(await R.getCell(`
const publicAvgPing = parseInt(
await R.getCell(
`
SELECT AVG(ping) FROM monitor_group, \`group\`, heartbeat
WHERE monitor_group.group_id = \`group\`.id
AND heartbeat.time > ${sqlHourOffset}
@@ -381,8 +384,9 @@ router.get("/api/badge/:id/avg-response/:duration?", cache("5 minutes"), async (
AND public = 1
AND heartbeat.monitor_id = ?
`,
[ -requestedDuration, requestedMonitorId ]
));
[-requestedDuration, requestedMonitorId]
)
);
const badgeValues = { style };
@@ -403,7 +407,7 @@ router.get("/api/badge/:id/avg-response/:duration?", cache("5 minutes"), async (
label ?? `Avg. Response (${requestedDuration}h)`,
labelSuffix,
]);
badgeValues.message = filterAndJoin([ prefix, avgPing, suffix ]);
badgeValues.message = filterAndJoin([prefix, avgPing, suffix]);
}
// build the SVG based on given values
@@ -442,13 +446,14 @@ router.get("/api/badge/:id/cert-exp", cache("5 minutes"), async (request, respon
const overrideValue = value && parseFloat(value);
let publicMonitor = await R.getRow(`
let publicMonitor = await R.getRow(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND monitor_group.monitor_id = ?
AND public = 1
`,
[ requestedMonitorId ]
[requestedMonitorId]
);
const badgeValues = { style };
@@ -459,9 +464,7 @@ router.get("/api/badge/:id/cert-exp", cache("5 minutes"), async (request, respon
badgeValues.message = "N/A";
badgeValues.color = badgeConstants.naColor;
} else {
const tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
requestedMonitorId,
]);
const tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [requestedMonitorId]);
if (!tlsInfoBean) {
// return a "No/Bad Cert" badge in naColor (grey), if no cert saved (does not save bad certs?)
@@ -487,12 +490,12 @@ router.get("/api/badge/:id/cert-exp", cache("5 minutes"), async (request, respon
// use a given, custom labelColor or use the default badge label color (defined by badge-maker)
badgeValues.labelColor = labelColor ?? "";
// build a label string. If a custom label is given, override the default one
badgeValues.label = filterAndJoin([
labelPrefix,
label ?? "Cert Exp.",
labelSuffix,
badgeValues.label = filterAndJoin([labelPrefix, label ?? "Cert Exp.", labelSuffix]);
badgeValues.message = filterAndJoin([
prefix,
date ? tlsInfo.certInfo.validTo : daysRemaining,
suffix,
]);
badgeValues.message = filterAndJoin([ prefix, date ? tlsInfo.certInfo.validTo : daysRemaining, suffix ]);
}
}
}
@@ -527,13 +530,14 @@ router.get("/api/badge/:id/response", cache("5 minutes"), async (request, respon
const overrideValue = value && parseFloat(value);
let publicMonitor = await R.getRow(`
let publicMonitor = await R.getRow(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND monitor_group.monitor_id = ?
AND public = 1
`,
[ requestedMonitorId ]
[requestedMonitorId]
);
const badgeValues = { style };
@@ -544,9 +548,7 @@ router.get("/api/badge/:id/response", cache("5 minutes"), async (request, respon
badgeValues.message = "N/A";
badgeValues.color = badgeConstants.naColor;
} else {
const heartbeat = await Monitor.getPreviousHeartbeat(
requestedMonitorId
);
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
if (!heartbeat.ping) {
// return a "N/A" badge in naColor (grey), if previous heartbeat has no ping
@@ -560,12 +562,8 @@ router.get("/api/badge/:id/response", cache("5 minutes"), async (request, respon
// use a given, custom labelColor or use the default badge label color (defined by badge-maker)
badgeValues.labelColor = labelColor ?? "";
// build a label string. If a custom label is given, override the default one
badgeValues.label = filterAndJoin([
labelPrefix,
label ?? "Response",
labelSuffix,
]);
badgeValues.message = filterAndJoin([ prefix, ping, suffix ]);
badgeValues.label = filterAndJoin([labelPrefix, label ?? "Response", labelSuffix]);
badgeValues.message = filterAndJoin([prefix, ping, suffix]);
}
}
@@ -596,7 +594,7 @@ function determineStatus(status, previousHeartbeat, maxretries, isUpsideDown, be
if (previousHeartbeat) {
if (previousHeartbeat.status === UP && status === DOWN) {
// Going Down
if ((maxretries > 0) && (previousHeartbeat.retries < maxretries)) {
if (maxretries > 0 && previousHeartbeat.retries < maxretries) {
// Retries available
bean.retries = previousHeartbeat.retries + 1;
bean.status = PENDING;
+34 -41
View File
@@ -43,9 +43,7 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
try {
// Get Status Page
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
let statusPage = await R.findOne("status_page", " slug = ? ", [slug]);
if (!statusPage) {
sendHttpError(response, "Status Page Not Found");
@@ -56,7 +54,6 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
// Response
response.json(statusPageData);
} catch (error) {
sendHttpError(response, error.message);
}
@@ -75,27 +72,29 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
slug = slug.toLowerCase();
let statusPageID = await StatusPage.slugToID(slug);
let monitorIDList = await R.getCol(`
let monitorIDList = await R.getCol(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND public = 1
AND \`group\`.status_page_id = ?
`, [
statusPageID
]);
`,
[statusPageID]
);
for (let monitorID of monitorIDList) {
let list = await R.getAll(`
let list = await R.getAll(
`
SELECT * FROM heartbeat
WHERE monitor_id = ?
ORDER BY time DESC
LIMIT 100
`, [
monitorID,
]);
`,
[monitorID]
);
list = R.convertToBeans("heartbeat", list);
heartbeatList[monitorID] = list.reverse().map(row => row.toPublicJSON());
heartbeatList[monitorID] = list.reverse().map((row) => row.toPublicJSON());
const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);
uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime;
@@ -103,9 +102,8 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
response.json({
heartbeatList,
uptimeList
uptimeList,
});
} catch (error) {
sendHttpError(response, error.message);
}
@@ -119,9 +117,7 @@ router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async
try {
// Get Status Page
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
let statusPage = await R.findOne("status_page", " slug = ? ", [slug]);
if (!statusPage) {
sendHttpError(response, "Not Found");
@@ -130,18 +126,17 @@ router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async
// Response
response.json({
"name": statusPage.title,
"start_url": "/status/" + statusPage.slug,
"display": "standalone",
"icons": [
name: statusPage.title,
start_url: "/status/" + statusPage.slug,
display: "standalone",
icons: [
{
"src": statusPage.icon,
"sizes": "128x128",
"type": "image/png"
}
]
src: statusPage.icon,
sizes: "128x128",
type: "image/png",
},
],
});
} catch (error) {
sendHttpError(response, error.message);
}
@@ -159,18 +154,19 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
downColor = badgeConstants.defaultDownColor,
partialColor = "#F6BE00",
maintenanceColor = "#808080",
style = badgeConstants.defaultStyle
style = badgeConstants.defaultStyle,
} = request.query;
try {
let monitorIDList = await R.getCol(`
let monitorIDList = await R.getCol(
`
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
WHERE monitor_group.group_id = \`group\`.id
AND public = 1
AND \`group\`.status_page_id = ?
`, [
statusPageID
]);
`,
[statusPageID]
);
let hasUp = false;
let hasDown = false;
@@ -178,14 +174,15 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
for (let monitorID of monitorIDList) {
// retrieve the latest heartbeat
let beat = await R.getAll(`
let beat = await R.getAll(
`
SELECT * FROM heartbeat
WHERE monitor_id = ?
ORDER BY time DESC
LIMIT 1
`, [
monitorID,
]);
`,
[monitorID]
);
// to be sure, when corresponding monitor not found
if (beat.length === 0) {
@@ -201,7 +198,6 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
} else {
hasDown = true;
}
}
const badgeValues = { style };
@@ -211,7 +207,6 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
badgeValues.message = "N/A";
badgeValues.color = badgeConstants.naColor;
} else {
if (hasMaintenance) {
badgeValues.label = label ? label : "";
@@ -230,7 +225,6 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
badgeValues.color = downColor;
badgeValues.message = "Down";
}
}
// build the svg based on given values
@@ -238,7 +232,6 @@ router.get("/api/status-page/:slug/badge", cache("5 minutes"), async (request, r
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
sendHttpError(response, error.message);
}