mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-16 03:04:40 -05:00
a little documentation
This commit is contained in:
parent
8b5997691e
commit
1c5bce8afa
@ -244,6 +244,8 @@ router.get("/api/badge/:id/:type", cache("5 minutes"), async (request, response)
|
|||||||
const badgeValues = {};
|
const badgeValues = {};
|
||||||
|
|
||||||
if (!publicMonitor) {
|
if (!publicMonitor) {
|
||||||
|
// return a "n/a" badge in grey, if monitor is not public / not available / non exsitant
|
||||||
|
|
||||||
badgeValues.message = "N/A";
|
badgeValues.message = "N/A";
|
||||||
badgeValues.color = "#CCCCCC";
|
badgeValues.color = "#CCCCCC";
|
||||||
} else {
|
} else {
|
||||||
@ -261,9 +263,9 @@ router.get("/api/badge/:id/:type", cache("5 minutes"), async (request, response)
|
|||||||
badgeValues.message = [prefix, `${uptime * 100} %`, suffix]
|
badgeValues.message = [prefix, `${uptime * 100} %`, suffix]
|
||||||
.filter((part) => part ?? part !== "")
|
.filter((part) => part ?? part !== "")
|
||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build the svg based on given values
|
||||||
const svg = makeBadge(badgeValues);
|
const svg = makeBadge(badgeValues);
|
||||||
|
|
||||||
response.type("image/svg+xml");
|
response.type("image/svg+xml");
|
||||||
|
@ -372,6 +372,16 @@ exports.errorLog = (error, outputToConsole = true) => {
|
|||||||
} catch (_) { }
|
} catch (_) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a color code in hex format based on a given percentage:
|
||||||
|
* 0% => hue = 10 => red
|
||||||
|
* 100% => hue = 90 => green
|
||||||
|
*
|
||||||
|
* @param {number} percentage, float, 0 to 1
|
||||||
|
* @param {number} maxHue, int
|
||||||
|
* @param {number} minHue, int
|
||||||
|
* @returns {string}, hex value
|
||||||
|
*/
|
||||||
exports.percentageToColor = (percentage, maxHue = 90, minHue = 10) => {
|
exports.percentageToColor = (percentage, maxHue = 90, minHue = 10) => {
|
||||||
const hue = percentage * (maxHue - minHue) + minHue;
|
const hue = percentage * (maxHue - minHue) + minHue;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user