mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-24 05:48:08 +08:00
Enhancement: refactor UptimeRobot widget (#6088)
This commit is contained in:
@@ -49,10 +49,12 @@ export default function Component({ service }) {
|
||||
|
||||
// single monitor
|
||||
const monitor = uptimerobotData.monitors[0];
|
||||
const logs = Array.isArray(monitor.logs) ? monitor.logs : [];
|
||||
const lastUpLog = logs.find((log) => log.type === 2);
|
||||
const lastDownLog = logs.find((log) => log.type === 1);
|
||||
|
||||
let status;
|
||||
let uptime = 0;
|
||||
let logIndex = 0;
|
||||
const hasLogs = Array.isArray(monitor.logs) && monitor.logs.length > 0;
|
||||
|
||||
switch (monitor.status) {
|
||||
case 0:
|
||||
@@ -63,8 +65,7 @@ export default function Component({ service }) {
|
||||
break;
|
||||
case 2:
|
||||
status = t("uptimerobot.up");
|
||||
uptime = t("common.duration", { value: hasLogs ? monitor.logs[0].duration : 0 });
|
||||
logIndex = 1;
|
||||
uptime = t("common.duration", { value: lastUpLog?.duration ?? 0 });
|
||||
break;
|
||||
case 8:
|
||||
status = t("uptimerobot.seemsdown");
|
||||
@@ -77,14 +78,14 @@ export default function Component({ service }) {
|
||||
break;
|
||||
}
|
||||
|
||||
const lastDown = hasLogs ? new Date(monitor.logs[logIndex].datetime * 1000).toLocaleString() : "";
|
||||
const downDuration = t("common.duration", { value: hasLogs ? monitor.logs[logIndex].duration : 0 });
|
||||
const hideDown = !hasLogs || (logIndex === 1 && monitor.logs[logIndex].type !== 1);
|
||||
const lastDown = lastDownLog ? new Date(lastDownLog.datetime * 1000).toLocaleString() : "";
|
||||
const downDuration = t("common.duration", { value: lastDownLog?.duration ?? 0 });
|
||||
const hideDown = !lastDownLog;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="uptimerobot.status" value={status} />
|
||||
{hasLogs && <Block label="uptimerobot.uptime" value={uptime} />}
|
||||
<Block label="uptimerobot.uptime" value={uptime} />
|
||||
{!hideDown && <Block label="uptimerobot.lastDown" value={lastDown} />}
|
||||
{!hideDown && <Block label="uptimerobot.downDuration" value={downDuration} />}
|
||||
</Container>
|
||||
|
||||
Reference in New Issue
Block a user