From 9757c3d8b6859780c0195ca90dcbfd69cbf1b226 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Fri, 1 May 2026 16:26:45 -0700 Subject: [PATCH] show newt version on site --- messages/en-US.json | 1 + server/routers/site/getSite.ts | 12 ++- src/components/SiteInfoCard.tsx | 178 +++++++++++++++++++++----------- 3 files changed, 128 insertions(+), 63 deletions(-) diff --git a/messages/en-US.json b/messages/en-US.json index eb4d3ae3c..c3e062edb 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -763,6 +763,7 @@ "newtEndpoint": "Endpoint", "newtId": "ID", "newtSecretKey": "Secret", + "newtVersion": "Version", "architecture": "Architecture", "sites": "Sites", "siteWgAnyClients": "Use any WireGuard client to connect. You will have to address internal resources using the peer IP.", diff --git a/server/routers/site/getSite.ts b/server/routers/site/getSite.ts index 45d49abe6..a16547b8d 100644 --- a/server/routers/site/getSite.ts +++ b/server/routers/site/getSite.ts @@ -42,9 +42,12 @@ async function query(siteId?: number, niceId?: string, orgId?: string) { } } -export type GetSiteResponse = NonNullable< - Awaited> ->["sites"] & { newtId: string | null }; +type SiteQueryRow = NonNullable>>; + +export type GetSiteResponse = SiteQueryRow["sites"] & { + newtId: string | null; + newtVersion: string | null; +}; registry.registerPath({ method: "get", @@ -100,7 +103,8 @@ export async function getSite( const data: GetSiteResponse = { ...site.sites, - newtId: site.newt ? site.newt.newtId : null + newtId: site.newt ? site.newt.newtId : null, + newtVersion: site.newt?.version ?? null }; return response(res, { diff --git a/src/components/SiteInfoCard.tsx b/src/components/SiteInfoCard.tsx index 56492ff54..91a924e58 100644 --- a/src/components/SiteInfoCard.tsx +++ b/src/components/SiteInfoCard.tsx @@ -1,6 +1,6 @@ "use client"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +import { Alert, AlertDescription } from "@/components/ui/alert"; import { useSiteContext } from "@app/hooks/useSiteContext"; import { InfoSection, @@ -9,77 +9,137 @@ import { InfoSectionTitle } from "@app/components/InfoSection"; import { useTranslations } from "next-intl"; -import { useEnvContext } from "@app/hooks/useEnvContext"; type SiteInfoCardProps = {}; -export default function SiteInfoCard({}: SiteInfoCardProps) { - const { site, updateSite } = useSiteContext(); - const t = useTranslations(); - const { env } = useEnvContext(); +function formatPublicEndpoint(endpoint: string) { + return endpoint.includes(":") + ? endpoint.substring(0, endpoint.lastIndexOf(":")) + : endpoint; +} - const getConnectionTypeString = (type: string) => { - if (type === "newt") { - return "Newt"; - } else if (type === "wireguard") { - return "WireGuard"; - } else if (type === "local") { - return t("local"); - } else { - return t("unknown"); - } - }; +export default function SiteInfoCard({}: SiteInfoCardProps) { + const { site } = useSiteContext(); + const t = useTranslations(); + + const identifierSection = ( + + {t("identifier")} + {site.niceId} + + ); + + const statusSection = ( + + {t("status")} + + {site.online ? ( +
+
+ {t("online")} +
+ ) : ( +
+
+ {t("offline")} +
+ )} +
+
+ ); + + const endpointSection = site.endpoint ? ( + + {t("publicIpEndpoint")} + + {formatPublicEndpoint(site.endpoint)} + + + ) : null; + + if (site.type === "newt") { + return ( + + + + {identifierSection} + {statusSection} + + + {t("connectionType")} + + Newt + + + + {t("newtVersion")} + + + {site.newtVersion + ? `v${site.newtVersion}` + : "-"} + + + {endpointSection} + + + + ); + } + + if (site.type === "wireguard") { + return ( + + + + {identifierSection} + {statusSection} + + + {t("connectionType")} + + WireGuard + + {endpointSection} + + + + ); + } + + if (site.type === "local") { + return ( + + + + {identifierSection} + + + {t("connectionType")} + + + {t("local")} + + + {endpointSection} + + + + ); + } return ( - - - {t("identifier")} - {site.niceId} - - {(site.type == "newt" || site.type == "wireguard") && ( - <> - - - {t("status")} - - - {site.online ? ( -
-
- {t("online")} -
- ) : ( -
-
- {t("offline")} -
- )} -
-
- - )} + + {identifierSection} {t("connectionType")} - - {getConnectionTypeString(site.type)} - + {t("unknown")} - {site.endpoint && ( - - - {t("publicIpEndpoint")} - - - {site.endpoint.includes(":") - ? site.endpoint.substring(0, site.endpoint.lastIndexOf(":")) - : site.endpoint} - - - )} + {endpointSection}