Enhancement: fritzbox uptime display (#2481)

pull/2483/head
Thorben 4 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"];
const formatUptime = (timestamp) => {
const hours = Math.floor(timestamp / 3600);
const minutes = Math.floor((timestamp % 3600) / 60);
const seconds = timestamp % 60;
const formatUptime = (uptimeInSeconds) => {
const days = Math.floor(uptimeInSeconds / (3600 * 24));
const hours = Math.floor((uptimeInSeconds % (3600 * 24)) / 3600);
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";
const minDuration = minutes > 0 ? `${minutes}m` : "00m";
const secDuration = seconds > 0 ? `${seconds}s` : "00s";
let uptimeStr = "";
if (days) {
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 }) {

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

Loading…
Cancel
Save