Feature: Headscale Service Widget (#4247)

This commit is contained in:
erelender 2024-11-05 20:02:33 +03:00 committed by GitHub
parent 6fd2b6b6dc
commit c12a5c01f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 90 additions and 0 deletions

View file

@ -39,6 +39,7 @@ export default async function credentialedProxyHandler(req, res, map) {
"authentik",
"cloudflared",
"ghostfolio",
"headscale",
"linkwarden",
"mealie",
"netalertx",

View file

@ -41,6 +41,7 @@ const components = {
gotify: dynamic(() => import("./gotify/component")),
grafana: dynamic(() => import("./grafana/component")),
hdhomerun: dynamic(() => import("./hdhomerun/component")),
headscale: dynamic(() => import("./headscale/component")),
peanut: dynamic(() => import("./peanut/component")),
homeassistant: dynamic(() => import("./homeassistant/component")),
homebox: dynamic(() => import("./homebox/component")),

View file

@ -0,0 +1,43 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: nodeData, error: nodeError } = useWidgetAPI(widget, "node");
if (nodeError) {
return <Container service={service} error={nodeError} />;
}
if (!nodeData) {
return (
<Container service={service}>
<Block label="headscale.name" />
<Block label="headscale.address" />
<Block label="headscale.last_seen" />
<Block label="headscale.status" />
</Container>
);
}
const {
givenName,
ipAddresses: [address],
lastSeen,
online,
} = nodeData.node;
return (
<Container service={service}>
<Block label="headscale.name" value={givenName} />
<Block label="headscale.address" value={address} />
<Block label="headscale.last_seen" value={t("common.relativeDate", { value: lastSeen })} />
<Block label="headscale.status" value={t(online ? "headscale.online" : "headscale.offline")} />
</Container>
);
}

View file

@ -0,0 +1,14 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = {
api: "{url}/api/v1/{endpoint}/{nodeId}",
proxyHandler: credentialedProxyHandler,
mappings: {
node: {
endpoint: "node",
},
},
};
export default widget;

View file

@ -35,6 +35,7 @@ import gluetun from "./gluetun/widget";
import gotify from "./gotify/widget";
import grafana from "./grafana/widget";
import hdhomerun from "./hdhomerun/widget";
import headscale from "./headscale/widget";
import homeassistant from "./homeassistant/widget";
import homebox from "./homebox/widget";
import homebridge from "./homebridge/widget";
@ -161,6 +162,7 @@ const widgets = {
gotify,
grafana,
hdhomerun,
headscale,
homeassistant,
homebox,
homebridge,