From 33d22fa8b31044ab45532c80916cd25844f00a44 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 12 Dec 2024 10:46:37 +0800 Subject: [PATCH] feat: ip info --- .env.example | 1 + app/(main)/ClientComponents/ServerIPInfo.tsx | 103 +++++++++++++++++-- app/(main)/server/[id]/page.tsx | 5 +- app/api/server-ip/route.ts | 7 ++ 4 files changed, 107 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 2dcb8ba..9fdaa54 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,4 @@ NEXT_PUBLIC_CustomDescription=NezhaDash is a dashboard for Nezha. NEXT_PUBLIC_Links='[{"link":"https://github.com/hamster1963/nezha-dash","name":"GitHub"},{"link":"https://buycoffee.top/coffee","name":"Buycoffee☕️"}]' NEXT_PUBLIC_DisableIndex=false NEXT_PUBLIC_ShowTagCount=false +NEXT_PUBLIC_ShowIpInfo=false diff --git a/app/(main)/ClientComponents/ServerIPInfo.tsx b/app/(main)/ClientComponents/ServerIPInfo.tsx index d36f202..e26bf66 100644 --- a/app/(main)/ClientComponents/ServerIPInfo.tsx +++ b/app/(main)/ClientComponents/ServerIPInfo.tsx @@ -1,24 +1,111 @@ "use client"; import { IPInfo } from "@/app/api/server-ip/route"; +import { Loader } from "@/components/loading/Loader"; +import { Card, CardContent } from "@/components/ui/card"; import { nezhaFetcher } from "@/lib/utils"; -import useSWR from "swr"; +import useSWRImmutable from "swr/immutable"; export default function ServerIPInfo({ server_id }: { server_id: number }) { - const { data } = useSWR( + const { data } = useSWRImmutable( `/api/server-ip?server_id=${server_id}`, nezhaFetcher, ); if (!data) { - return
Loading...
; + return ( +
+ +
+ ); } - console.log(data); - return ( -
-

Server IP Info

-
+ <> +
+ + +
+

{"ASN"}

+
+ {data.asn.autonomous_system_organization} +
+
+
+
+ + +
+

{"Origin ASN"}

+
+ AS{data.asn.autonomous_system_number} +
+
+
+
+ + +
+

+ {"Registered Country"} +

+
+ {data.city.registered_country?.names.en} +
+
+
+
+ + +
+

{"Time Zone"}

+
{data.city.location?.time_zone}
+
+
+
+ {data.city.postal && ( + + +
+

{"Postal"}

+
{data.city.postal?.code}
+
+
+
+ )} + + +
+

{"ISO"}

+
{data.city.country?.iso_code}
+
+
+
+ + +
+

{"City"}

+
{data.city.city?.names.en}
+
+
+
+ + +
+

{"Longitude"}

+
{data.city.location?.longitude}
+
+
+
+ + +
+

{"Latitude"}

+
{data.city.location?.latitude}
+
+
+
+
+ ); } diff --git a/app/(main)/server/[id]/page.tsx b/app/(main)/server/[id]/page.tsx index 70127a9..8500c24 100644 --- a/app/(main)/server/[id]/page.tsx +++ b/app/(main)/server/[id]/page.tsx @@ -5,6 +5,7 @@ import ServerDetailChartClient from "@/app/(main)/ClientComponents/ServerDetailC import ServerDetailClient from "@/app/(main)/ClientComponents/ServerDetailClient"; import TabSwitch from "@/components/TabSwitch"; import { Separator } from "@/components/ui/separator"; +import getEnv from "@/lib/env-entry"; import { use, useState } from "react"; import ServerIPInfo from "../../ClientComponents/ServerIPInfo"; @@ -16,7 +17,6 @@ export default function Page(props: { params: Promise<{ id: string }> }) { return (
-
@@ -35,6 +35,9 @@ export default function Page(props: { params: Promise<{ id: string }> }) { />
+ {getEnv("NEXT_PUBLIC_ShowIpInfo") && ( + + )}