mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-13 00:18:50 +00:00
Rework uptime kuma remove proxy display more info
This commit is contained in:
parent
c3d15a61c3
commit
015d7dac52
4 changed files with 45 additions and 121 deletions
|
@ -4,42 +4,52 @@ import Container from "components/services/widget/container";
|
|||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import Block from "components/services/widget/block";
|
||||
|
||||
const Status = {
|
||||
good: "uptimekuma.good",
|
||||
warn: "uptimekuma.warn",
|
||||
bad: "uptimekuma.bad",
|
||||
unknown: "uptimekuma.unknown",
|
||||
};
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statusData, error: statusError } = useWidgetAPI(widget);
|
||||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status_page");
|
||||
const { data: heartbeatData, error: heartbeatError } = useWidgetAPI(widget, "heartbeat");
|
||||
|
||||
if (statusError) {
|
||||
return <Container error={statusError} />;
|
||||
if (statusError || heartbeatError) {
|
||||
return <Container error={statusError ?? heartbeatError} />;
|
||||
}
|
||||
|
||||
if (!statusData) {
|
||||
if (!statusData || !heartbeatData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="uptimekuma.status"/>
|
||||
<Block label="uptimekuma.up"/>
|
||||
<Block label="uptimekuma.down"/>
|
||||
<Block label="uptimekuma.uptime"/>
|
||||
<Block label="uptimekuma.incidents"/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
if (statusData.icon) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
service.icon = statusData.icon;
|
||||
}
|
||||
let sitesUp = 0;
|
||||
let sitesDown = 0;
|
||||
Object.values(heartbeatData.heartbeatList).forEach((siteList) => {
|
||||
const lastHeartbeat = siteList[siteList.length - 1];
|
||||
if (lastHeartbeat?.status === 1) {
|
||||
sitesUp += 1;
|
||||
} else {
|
||||
sitesDown += 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Adapted from https://github.com/bastienwirtz/homer/blob/b7cd8f9482e6836a96b354b11595b03b9c3d67cd/src/components/services/UptimeKuma.vue#L105
|
||||
const uptimeList = Object.values(heartbeatData.uptimeList);
|
||||
const percent = uptimeList.reduce((a, b) => a + b, 0) / uptimeList.length || 0;
|
||||
const uptime = (percent * 100).toFixed(1);
|
||||
const incidentTime = statusData.incident ? (Math.abs(new Date(statusData.incident?.createdDate) - new Date()) / 1000) / (60 * 60) : null;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="uptimekuma.status" value={statusData.incident ? statusData.incident : t(Status[statusData.message])} />
|
||||
<Block label="uptimekuma.uptime" value={t("common.number", { value: statusData.uptime, decimals: 1 })} />
|
||||
<Block label="uptimekuma.up" value={t("common.number", { value: sitesUp })} />
|
||||
<Block label="uptimekuma.down" value={t("common.number", { value: sitesDown })} />
|
||||
<Block label="uptimekuma.uptime" value={t("common.percent", { value: uptime })} />
|
||||
{incidentTime && <Block label="uptimekuma.incident" value={t("common.number", { value: Math.round(incidentTime) }) + t("uptimekuma.m")} />}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue