Repository: louislam/uptime-kuma
File: server/routers/api-router.js (JavaScript)

Code before:

        const badgeValues = { style };

        if (!publicMonitor) {
            // return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant

            badgeValues.message = "N/A";
            badgeValues.color = badgeConstants.naColor;
        } else {
            const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
            const state = overrideValue !== undefined ? overrideValue : heartbeat.status;

            badgeValues.label = label ?? "";
            switch (state) {
                case 1:
                    badgeValues.color = upColor;
                    badgeValues.message = upLabel;
                    break;
                case 3:
                    badgeValues.color = maintenanceColor;
                    badgeValues.message = maintenanceLabel;
                    break;
                case 0:
                    badgeValues.color = downColor;
                    badgeValues.message = downLabel;
                    break;
                default:
                    badgeValues.color = badgeConstants.naColor;
                    badgeValues.message = "N/A";
            }
        }

        // build the svg based on given values
        const svg = makeBadge(badgeValues);

        response.type("image/svg+xml");
        response.send(svg);
    } catch (error) {
        send403(response, error.message);
    }
});

router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (request, response) => {
    allowAllOrigin(response);

    const {
        label,
        labelPrefix,
        labelSuffix = badgeConstants.defaultUptimeLabelSuffix,
        prefix,
        suffix = badgeConstants.defaultUptimeValueSuffix,

Review comment (suggestion):
(just style, so subjective:)
Is there a reason these cases are unorderd? I think this could be a little clearer

```suggestion
                case 0:
                    badgeValues.color = downColor;
                    badgeValues.message = downLabel;
                    break;
                case 1:
                    badgeValues.color = upColor;
                    badgeValues.message = upLabel;
                    break;
                case 3:
                    badgeValues.color = maintenanceColor;
                    badgeValues.message = maintenanceLabel;
                    break;
```

Code after:
        [ requestedMonitorId ]
        );

        const badgeValues = { style };

        if (!publicMonitor) {
            // return a "N/A" badge in naColor (grey), if monitor is not public / not available / non exsitant

            badgeValues.message = "N/A";
            badgeValues.color = badgeConstants.naColor;
        } else {
            const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
            const state = overrideValue !== undefined ? overrideValue : heartbeat.status;

            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
        const svg = makeBadge(badgeValues);

        response.type("image/svg+xml");
        response.send(svg);
    } catch (error) {
        send403(response, error.message);
    }
});

router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (request, response) => {
    allowAllOrigin(response);