feat: use full region name

This commit is contained in:
hamster1963 2025-01-05 22:05:57 +08:00
parent 51689d482e
commit a5ed28c0f1
12 changed files with 92 additions and 28 deletions

View File

@ -27,7 +27,13 @@ interface ResultItem {
[key: string]: number [key: string]: number
} }
export function NetworkChartClient({ server_id, show }: { server_id: number; show: boolean }) { export function NetworkChartClient({
server_id,
show,
}: {
server_id: number
show: boolean
}) {
const t = useTranslations("NetworkChartClient") const t = useTranslations("NetworkChartClient")
const { data, error } = useSWR<NezhaAPIMonitor[]>( const { data, error } = useSWR<NezhaAPIMonitor[]>(
`/api/monitor?server_id=${server_id}`, `/api/monitor?server_id=${server_id}`,

View File

@ -84,7 +84,13 @@ export default function ServerDetailChartClient({
) )
} }
function CpuChart({ history, data }: { history: ServerDataWithTimestamp[]; data: NezhaAPISafe }) { function CpuChart({
history,
data,
}: {
history: ServerDataWithTimestamp[]
data: NezhaAPISafe
}) {
const [cpuChartData, setCpuChartData] = useState([] as cpuChartData[]) const [cpuChartData, setCpuChartData] = useState([] as cpuChartData[])
const hasInitialized = useRef(false) const hasInitialized = useRef(false)
const [historyLoaded, setHistoryLoaded] = useState(false) const [historyLoaded, setHistoryLoaded] = useState(false)
@ -309,7 +315,13 @@ function ProcessChart({
) )
} }
function MemChart({ data, history }: { data: NezhaAPISafe; history: ServerDataWithTimestamp[] }) { function MemChart({
data,
history,
}: {
data: NezhaAPISafe
history: ServerDataWithTimestamp[]
}) {
const t = useTranslations("ServerDetailChartClient") const t = useTranslations("ServerDetailChartClient")
const [memChartData, setMemChartData] = useState([] as memChartData[]) const [memChartData, setMemChartData] = useState([] as memChartData[])
const hasInitialized = useRef(false) const hasInitialized = useRef(false)
@ -463,7 +475,13 @@ function MemChart({ data, history }: { data: NezhaAPISafe; history: ServerDataWi
) )
} }
function DiskChart({ data, history }: { data: NezhaAPISafe; history: ServerDataWithTimestamp[] }) { function DiskChart({
data,
history,
}: {
data: NezhaAPISafe
history: ServerDataWithTimestamp[]
}) {
const t = useTranslations("ServerDetailChartClient") const t = useTranslations("ServerDetailChartClient")
const [diskChartData, setDiskChartData] = useState([] as diskChartData[]) const [diskChartData, setDiskChartData] = useState([] as diskChartData[])
const hasInitialized = useRef(false) const hasInitialized = useRef(false)

View File

@ -7,11 +7,16 @@ import { ServerDetailLoading } from "@/components/loading/ServerDetailLoading"
import { Badge } from "@/components/ui/badge" import { Badge } from "@/components/ui/badge"
import { Card, CardContent } from "@/components/ui/card" import { Card, CardContent } from "@/components/ui/card"
import { cn, formatBytes } from "@/lib/utils" import { cn, formatBytes } from "@/lib/utils"
import countries from "i18n-iso-countries"
import { useTranslations } from "next-intl" import { useTranslations } from "next-intl"
import { notFound, useRouter } from "next/navigation" import { notFound, useRouter } from "next/navigation"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
export default function ServerDetailClient({ server_id }: { server_id: number }) { export default function ServerDetailClient({
server_id,
}: {
server_id: number
}) {
const t = useTranslations("ServerDetailClient") const t = useTranslations("ServerDetailClient")
const router = useRouter() const router = useRouter()
@ -56,6 +61,8 @@ export default function ServerDetailClient({ server_id }: { server_id: number })
if (!data) return <ServerDetailLoading /> if (!data) return <ServerDetailLoading />
countries.registerLocale(require("i18n-iso-countries/langs/en.json"))
return ( return (
<div> <div>
<div <div
@ -134,20 +141,24 @@ export default function ServerDetailClient({ server_id }: { server_id: number })
</section> </section>
</CardContent> </CardContent>
</Card> </Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none"> {data?.host.CountryCode && (
<CardContent className="px-1.5 py-1"> <Card className="rounded-[10px] bg-transparent border-none shadow-none">
<section className="flex flex-col items-start gap-0.5"> <CardContent className="px-1.5 py-1">
<p className="text-xs text-muted-foreground">{t("Region")}</p> <section className="flex flex-col items-start gap-0.5">
<section className="flex items-start gap-1"> <p className="text-xs text-muted-foreground">{t("Region")}</p>
<div className="text-xs text-start">{data?.host.CountryCode.toUpperCase()}</div> <section className="flex items-start gap-1">
<ServerFlag <div className="text-xs text-start">
className="text-[11px] -mt-[1px]" {countries.getName(data?.host.CountryCode, "en")}
country_code={data?.host.CountryCode} </div>
/> <ServerFlag
className="text-[11px] -mt-[1px]"
country_code={data?.host.CountryCode}
/>
</section>
</section> </section>
</section> </CardContent>
</CardContent> </Card>
</Card> )}
</section> </section>
<section className="flex flex-wrap gap-2 mt-1"> <section className="flex flex-wrap gap-2 mt-1">
{data?.host.Platform && ( {data?.host.Platform && (

View File

@ -45,7 +45,11 @@ export const viewport: Viewport = {
userScalable: false, userScalable: false,
} }
export default async function LocaleLayout({ children }: { children: React.ReactNode }) { export default async function LocaleLayout({
children,
}: {
children: React.ReactNode
}) {
const locale = await getLocale() const locale = await getLocale()
const messages = await getMessages() const messages = await getMessages()

BIN
bun.lockb

Binary file not shown.

View File

@ -9,7 +9,11 @@ import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils"
import { useTranslations } from "next-intl" import { useTranslations } from "next-intl"
import Link from "next/link" import Link from "next/link"
export default function ServerCard({ serverInfo }: { serverInfo: NezhaAPISafe }) { export default function ServerCard({
serverInfo,
}: {
serverInfo: NezhaAPISafe
}) {
const t = useTranslations("ServerCard") const t = useTranslations("ServerCard")
const { id, name, country_code, online, cpu, up, down, mem, stg, host } = const { id, name, country_code, online, cpu, up, down, mem, stg, host } =
formatNezhaInfo(serverInfo) formatNezhaInfo(serverInfo)

View File

@ -10,7 +10,11 @@ import Link from "next/link"
import { Separator } from "./ui/separator" import { Separator } from "./ui/separator"
export default function ServerCardInline({ serverInfo }: { serverInfo: NezhaAPISafe }) { export default function ServerCardInline({
serverInfo,
}: {
serverInfo: NezhaAPISafe
}) {
const t = useTranslations("ServerCard") const t = useTranslations("ServerCard")
const { id, name, country_code, online, cpu, up, down, mem, stg, host } = const { id, name, country_code, online, cpu, up, down, mem, stg, host } =
formatNezhaInfo(serverInfo) formatNezhaInfo(serverInfo)

View File

@ -19,7 +19,10 @@ export default function Switch({
const scrollRef = useRef<HTMLDivElement>(null) const scrollRef = useRef<HTMLDivElement>(null)
const tagRefs = useRef(allTag.map(() => createRef<HTMLDivElement>())) const tagRefs = useRef(allTag.map(() => createRef<HTMLDivElement>()))
const t = useTranslations("ServerListClient") const t = useTranslations("ServerListClient")
const [indicator, setIndicator] = useState<{ x: number; w: number }>({ x: 0, w: 0 }) const [indicator, setIndicator] = useState<{ x: number; w: number }>({
x: 0,
w: 0,
})
useEffect(() => { useEffect(() => {
const savedTag = sessionStorage.getItem("selectedTag") const savedTag = sessionStorage.getItem("selectedTag")

View File

@ -14,7 +14,10 @@ export default function TabSwitch({
setCurrentTab: (tab: string) => void setCurrentTab: (tab: string) => void
}) { }) {
const t = useTranslations("TabSwitch") const t = useTranslations("TabSwitch")
const [indicator, setIndicator] = useState<{ x: number; w: number }>({ x: 0, w: 0 }) const [indicator, setIndicator] = useState<{ x: number; w: number }>({
x: 0,
w: 0,
})
const tabRefs = useRef<(HTMLDivElement | null)[]>([]) const tabRefs = useRef<(HTMLDivElement | null)[]>([])
useEffect(() => { useEffect(() => {

View File

@ -37,19 +37,25 @@ export function ModeToggle() {
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent className="flex flex-col gap-0.5" align="end"> <DropdownMenuContent className="flex flex-col gap-0.5" align="end">
<DropdownMenuItem <DropdownMenuItem
className={cn("rounded-b-[5px]", { "gap-3 bg-muted font-semibold": theme === "light" })} className={cn("rounded-b-[5px]", {
"gap-3 bg-muted font-semibold": theme === "light",
})}
onSelect={(e) => handleSelect(e, "light")} onSelect={(e) => handleSelect(e, "light")}
> >
{t("Light")} {theme === "light" && <CheckCircleIcon className="size-4" />} {t("Light")} {theme === "light" && <CheckCircleIcon className="size-4" />}
</DropdownMenuItem> </DropdownMenuItem>
<DropdownMenuItem <DropdownMenuItem
className={cn("rounded-[5px]", { "gap-3 bg-muted font-semibold": theme === "dark" })} className={cn("rounded-[5px]", {
"gap-3 bg-muted font-semibold": theme === "dark",
})}
onSelect={(e) => handleSelect(e, "dark")} onSelect={(e) => handleSelect(e, "dark")}
> >
{t("Dark")} {theme === "dark" && <CheckCircleIcon className="size-4" />} {t("Dark")} {theme === "dark" && <CheckCircleIcon className="size-4" />}
</DropdownMenuItem> </DropdownMenuItem>
<DropdownMenuItem <DropdownMenuItem
className={cn("rounded-t-[5px]", { "gap-3 bg-muted font-semibold": theme === "system" })} className={cn("rounded-t-[5px]", {
"gap-3 bg-muted font-semibold": theme === "system",
})}
onSelect={(e) => handleSelect(e, "system")} onSelect={(e) => handleSelect(e, "system")}
> >
{t("System")} {theme === "system" && <CheckCircleIcon className="size-4" />} {t("System")} {theme === "system" && <CheckCircleIcon className="size-4" />}

View File

@ -126,7 +126,11 @@ export async function GetServerMonitor({ server_id }: { server_id: number }) {
} }
} }
export async function GetServerIP({ server_id }: { server_id: number }): Promise<string> { export async function GetServerIP({
server_id,
}: {
server_id: number
}): Promise<string> {
let nezhaBaseUrl = getEnv("NezhaBaseUrl") let nezhaBaseUrl = getEnv("NezhaBaseUrl")
if (!nezhaBaseUrl) { if (!nezhaBaseUrl) {
console.error("NezhaBaseUrl is not set") console.error("NezhaBaseUrl is not set")

View File

@ -40,6 +40,7 @@
"d3-selection": "^3.0.0", "d3-selection": "^3.0.0",
"eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-simple-import-sort": "^12.1.1",
"flag-icons": "^7.2.3", "flag-icons": "^7.2.3",
"i18n-iso-countries": "^7.13.0",
"lucide-react": "^0.454.0", "lucide-react": "^0.454.0",
"luxon": "^3.5.0", "luxon": "^3.5.0",
"maxmind": "^4.3.23", "maxmind": "^4.3.23",
@ -73,7 +74,7 @@
"postcss": "^8.4.49", "postcss": "^8.4.49",
"tailwindcss": "^4.0.0-beta.8", "tailwindcss": "^4.0.0-beta.8",
"typescript": "^5.7.2", "typescript": "^5.7.2",
"vercel": "^39.2.4" "vercel": "^39.2.5"
}, },
"overrides": { "overrides": {
"react-is": "^19.0.0-rc-69d4b800-20241021" "react-is": "^19.0.0-rc-69d4b800-20241021"