mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-14 00:40:30 +00:00
Run pre-commit hooks over existing codebase
Co-Authored-By: Ben Phelps <ben@phelps.io>
This commit is contained in:
parent
fa50bbad9c
commit
19c25713c4
387 changed files with 4785 additions and 4109 deletions
|
@ -5,59 +5,69 @@ import Block from "components/services/widget/block";
|
|||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stat/sites");
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stat/sites");
|
||||
|
||||
if (statsError) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
if (statsError) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
|
||||
const defaultSite = widget.site ? statsData?.data.find(s => s.desc === widget.site) : statsData?.data?.find(s => s.name === "default");
|
||||
|
||||
if (!defaultSite) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="unifi.uptime" />
|
||||
<Block label="unifi.wan" />
|
||||
<Block label="unifi.lan_users" />
|
||||
<Block label="unifi.wlan_users" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const wan = defaultSite.health.find(h => h.subsystem === "wan");
|
||||
const lan = defaultSite.health.find(h => h.subsystem === "lan");
|
||||
const wlan = defaultSite.health.find(h => h.subsystem === "wlan");
|
||||
[wan, lan, wlan].forEach(s => {
|
||||
s.up = s.status === "ok" // eslint-disable-line no-param-reassign
|
||||
s.show = s.status !== "unknown" // eslint-disable-line no-param-reassign
|
||||
});
|
||||
|
||||
const uptime = wan["gw_system-stats"] ? `${t("common.number", { value: wan["gw_system-stats"].uptime / 86400, maximumFractionDigits: 1 })} ${t("unifi.days")}` : null;
|
||||
|
||||
if (!(wan.show || lan.show || wlan.show || uptime)) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block value={ t("unifi.empty_data") } />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
const defaultSite = widget.site
|
||||
? statsData?.data.find((s) => s.desc === widget.site)
|
||||
: statsData?.data?.find((s) => s.name === "default");
|
||||
|
||||
if (!defaultSite) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
{uptime && <Block label="unifi.uptime" value={ uptime } />}
|
||||
{wan.show && <Block label="unifi.wan" value={ wan.status === "ok" ? t("unifi.up") : t("unifi.down") } />}
|
||||
|
||||
{lan.show && <Block label="unifi.lan_users" value={ t("common.number", { value: lan.num_user }) } />}
|
||||
{lan.show && !wlan.show && <Block label="unifi.lan_devices" value={ t("common.number", { value: lan.num_adopted }) } />}
|
||||
{lan.show && !wlan.show && <Block label="unifi.lan" value={ lan.up ? t("unifi.up") : t("unifi.down") } />}
|
||||
|
||||
{wlan.show && <Block label="unifi.wlan_users" value={ t("common.number", { value: wlan.num_user }) } />}
|
||||
{wlan.show && !lan.show && <Block label="unifi.wlan_devices" value={ t("common.number", { value: wlan.num_adopted }) } />}
|
||||
{wlan.show && !lan.show && <Block label="unifi.wlan" value={ wlan.up ? t("unifi.up") : t("unifi.down") } />}
|
||||
</Container>
|
||||
<Container service={service}>
|
||||
<Block label="unifi.uptime" />
|
||||
<Block label="unifi.wan" />
|
||||
<Block label="unifi.lan_users" />
|
||||
<Block label="unifi.wlan_users" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const wan = defaultSite.health.find((h) => h.subsystem === "wan");
|
||||
const lan = defaultSite.health.find((h) => h.subsystem === "lan");
|
||||
const wlan = defaultSite.health.find((h) => h.subsystem === "wlan");
|
||||
[wan, lan, wlan].forEach((s) => {
|
||||
s.up = s.status === "ok"; // eslint-disable-line no-param-reassign
|
||||
s.show = s.status !== "unknown"; // eslint-disable-line no-param-reassign
|
||||
});
|
||||
|
||||
const uptime = wan["gw_system-stats"]
|
||||
? `${t("common.number", { value: wan["gw_system-stats"].uptime / 86400, maximumFractionDigits: 1 })} ${t(
|
||||
"unifi.days",
|
||||
)}`
|
||||
: null;
|
||||
|
||||
if (!(wan.show || lan.show || wlan.show || uptime)) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block value={t("unifi.empty_data")} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
{uptime && <Block label="unifi.uptime" value={uptime} />}
|
||||
{wan.show && <Block label="unifi.wan" value={wan.status === "ok" ? t("unifi.up") : t("unifi.down")} />}
|
||||
|
||||
{lan.show && <Block label="unifi.lan_users" value={t("common.number", { value: lan.num_user })} />}
|
||||
{lan.show && !wlan.show && (
|
||||
<Block label="unifi.lan_devices" value={t("common.number", { value: lan.num_adopted })} />
|
||||
)}
|
||||
{lan.show && !wlan.show && <Block label="unifi.lan" value={lan.up ? t("unifi.up") : t("unifi.down")} />}
|
||||
|
||||
{wlan.show && <Block label="unifi.wlan_users" value={t("common.number", { value: wlan.num_user })} />}
|
||||
{wlan.show && !lan.show && (
|
||||
<Block label="unifi.wlan_devices" value={t("common.number", { value: wlan.num_adopted })} />
|
||||
)}
|
||||
{wlan.show && !lan.show && <Block label="unifi.wlan" value={wlan.up ? t("unifi.up") : t("unifi.down")} />}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@ const logger = createLogger(proxyName);
|
|||
|
||||
async function getWidget(req) {
|
||||
const { group, service, type } = req.query;
|
||||
|
||||
|
||||
let widget = null;
|
||||
if (type === "unifi_console") { // info widget
|
||||
if (type === "unifi_console") {
|
||||
// info widget
|
||||
const index = req.query?.query ? JSON.parse(req.query.query).index : undefined;
|
||||
widget = await getPrivateWidgetOptions(type, index);
|
||||
if (!widget) {
|
||||
|
@ -30,7 +31,7 @@ async function getWidget(req) {
|
|||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
widget = await getServiceWidget(group, service);
|
||||
|
||||
if (!widget) {
|
||||
|
@ -43,7 +44,7 @@ async function getWidget(req) {
|
|||
}
|
||||
|
||||
async function login(widget, csrfToken) {
|
||||
const endpoint = (widget.prefix === udmpPrefix) ? "auth/login" : "login";
|
||||
const endpoint = widget.prefix === udmpPrefix ? "auth/login" : "login";
|
||||
const api = widgets?.[widget.type]?.api?.replace("{prefix}", ""); // no prefix for login url
|
||||
const loginUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||
const loginBody = { username: widget.username, password: widget.password, remember: true };
|
||||
|
@ -93,9 +94,9 @@ export default async function unifiProxyHandler(req, res) {
|
|||
setCookieHeader(url, params);
|
||||
|
||||
[status, contentType, data, responseHeaders] = await httpProxy(url, params);
|
||||
|
||||
|
||||
if (status === 401) {
|
||||
logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login.");
|
||||
logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login.");
|
||||
if (responseHeaders?.["x-csrf-token"]) {
|
||||
csrfToken = responseHeaders["x-csrf-token"];
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ export default async function unifiProxyHandler(req, res) {
|
|||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP %d logging in to Unifi. Data: %s", status, data);
|
||||
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
|
||||
return res.status(status).json({ error: { message: `HTTP Error ${status}`, url, data } });
|
||||
}
|
||||
|
||||
const json = JSON.parse(data.toString());
|
||||
|
@ -121,7 +122,7 @@ export default async function unifiProxyHandler(req, res) {
|
|||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP %d getting data from Unifi endpoint %s. Data: %s", status, url.href, data);
|
||||
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
|
||||
return res.status(status).json({ error: { message: `HTTP Error ${status}`, url, data } });
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
|
|
|
@ -8,7 +8,7 @@ const widget = {
|
|||
"stat/sites": {
|
||||
endpoint: "stat/sites",
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue