mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-26 22:56:52 +02:00
Merge pull request #2525 from chakflying/fix/maintenance-badge
Fix: Add support for pending & maintenance in badges
This commit is contained in:
commit
fca0198d35
@ -5,6 +5,8 @@ const badgeConstants = {
|
||||
naColor: "#999",
|
||||
defaultUpColor: "#66c20a",
|
||||
defaultDownColor: "#c2290a",
|
||||
defaultPendingColor: "#f8a306",
|
||||
defaultMaintenanceColor: "#1747f5",
|
||||
defaultPingColor: "blue", // as defined by badge-maker / shields.io
|
||||
defaultStyle: "flat",
|
||||
defaultPingValueSuffix: "ms",
|
||||
|
@ -111,8 +111,12 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
|
||||
label,
|
||||
upLabel = "Up",
|
||||
downLabel = "Down",
|
||||
pendingLabel = "Pending",
|
||||
maintenanceLabel = "Maintenance",
|
||||
upColor = badgeConstants.defaultUpColor,
|
||||
downColor = badgeConstants.defaultDownColor,
|
||||
pendingColor = badgeConstants.defaultPendingColor,
|
||||
maintenanceColor = badgeConstants.defaultMaintenanceColor,
|
||||
style = badgeConstants.defaultStyle,
|
||||
value, // for demo purpose only
|
||||
} = request.query;
|
||||
@ -139,11 +143,30 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
|
||||
badgeValues.color = badgeConstants.naColor;
|
||||
} else {
|
||||
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
|
||||
const state = overrideValue !== undefined ? overrideValue : heartbeat.status === 1;
|
||||
const state = overrideValue !== undefined ? overrideValue : heartbeat.status;
|
||||
|
||||
badgeValues.label = label ? label : "";
|
||||
badgeValues.color = state ? upColor : downColor;
|
||||
badgeValues.message = label ?? state ? upLabel : downLabel;
|
||||
badgeValues.label = label ?? "";
|
||||
switch (state) {
|
||||
case 0:
|
||||
badgeValues.color = downColor;
|
||||
badgeValues.message = downLabel;
|
||||
break;
|
||||
case 1:
|
||||
badgeValues.color = upColor;
|
||||
badgeValues.message = upLabel;
|
||||
break;
|
||||
case 2:
|
||||
badgeValues.color = pendingColor;
|
||||
badgeValues.message = pendingLabel;
|
||||
break;
|
||||
case 3:
|
||||
badgeValues.color = maintenanceColor;
|
||||
badgeValues.message = maintenanceLabel;
|
||||
break;
|
||||
default:
|
||||
badgeValues.color = badgeConstants.naColor;
|
||||
badgeValues.message = "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
// build the svg based on given values
|
||||
|
Loading…
Reference in New Issue
Block a user