Enhancement: fritzbox uptime display (#2481)

pull/2483/head
Thorben 5 months ago committed by GitHub
parent aeaf36e0cf
commit 24e25e8953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,16 +6,28 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export const fritzboxDefaultFields = ["connectionStatus", "uptime", "maxDown", "maxUp"]; export const fritzboxDefaultFields = ["connectionStatus", "uptime", "maxDown", "maxUp"];
const formatUptime = (timestamp) => { const formatUptime = (uptimeInSeconds) => {
const hours = Math.floor(timestamp / 3600); const days = Math.floor(uptimeInSeconds / (3600 * 24));
const minutes = Math.floor((timestamp % 3600) / 60); const hours = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600);
const seconds = timestamp % 60; const minutes = Math.floor((uptimeInSeconds % 3600) / 60);
const seconds = Math.floor(uptimeInSeconds) % 60;
const format = (num) => String(num).padStart(2, "0");
const hourDuration = hours > 0 ? `${hours}h` : "00h"; let uptimeStr = "";
const minDuration = minutes > 0 ? `${minutes}m` : "00m"; if (days) {
const secDuration = seconds > 0 ? `${seconds}s` : "00s"; uptimeStr += `${days}d`;
}
if (uptimeInSeconds >= 3600) {
uptimeStr += `${format(hours)}h`;
}
if (uptimeInSeconds >= 60) {
uptimeStr += `${format(minutes)}m`;
}
if (!days) {
uptimeStr += `${format(seconds)}s `;
}
return hourDuration + minDuration + secDuration; return uptimeStr;
}; };
export default function Component({ service }) { export default function Component({ service }) {

@ -50,12 +50,12 @@ export default async function fritzboxProxyHandler(req, res) {
const serviceWidget = await getServiceWidget(group, service); const serviceWidget = await getServiceWidget(group, service);
if (!serviceWidget) { if (!serviceWidget) {
res.status(500).json({ error: "Service widget not found" }); res.status(500).json({ error: { message: "Service widget not found" } });
return; return;
} }
if (!serviceWidget.url) { if (!serviceWidget.url) {
res.status(500).json({ error: "Service widget url not configured" }); res.status(500).json({ error: { message: "Service widget url not configured" } });
return; return;
} }
@ -91,6 +91,6 @@ export default async function fritzboxProxyHandler(req, res) {
}); });
}) })
.catch((error) => { .catch((error) => {
res.status(500).json({ error: error.message }); res.status(500).json({ error: { message: error.message } });
}); });
} }

Loading…
Cancel
Save