import { Card } from "@/app/components/card"; import { generateEmbed } from "@/common/embed"; import { capitalizeFirstLetter } from "@/common/string-utils"; import { cn } from "@/common/utils"; import { CachedEndpointStatus, getMojangEndpointStatus, Status } from "mcutils-library"; import { Metadata, Viewport } from "next"; import Link from "next/link"; import { ReactElement } from "react"; import { Colors } from "@/common/colors"; /** * Force the page to be dynamic, so it will be regenerated on every request */ export const dynamic = "force-dynamic"; /** * Gets the color of the status * * @param status the status of the endpoint * @returns the color of the status */ function getColor(status: any): string { switch (status) { case "ONLINE": return "text-green-500"; case "DEGRADED": return "text-yellow-500"; case "OFFLINE": return "text-red-500"; default: return "text-gray-500"; } } /** * Formats the status * * @param status the status of the endpoint * @returns the formatted status */ function formatStatus(status: any): string { return capitalizeFirstLetter(status.toLowerCase()); } export async function generateViewport(): Promise { const { endpoints } = await getMojangEndpointStatus(); let warning = false; for (const endpoint of endpoints) { if (endpoint.status != Status.ONLINE) { warning = true; break; } } return { themeColor: warning ? Colors.yellow : Colors.green, }; } export async function generateMetadata(): Promise { const { endpoints } = await getMojangEndpointStatus(); let description = "Current Mojang API Status:\n"; for (const endpoint of endpoints) { const { name, hostname, status } = endpoint; description += `${name} (${hostname}): ${status}\n`; } return generateEmbed({ title: "Mojang Status", description: description, }); } export default async function Page(): Promise { const { endpoints } = await getMojangEndpointStatus(); return (

Mojang Status

The current status of Mojang Services

{endpoints.length == 0 &&

Unable to fetch endpoint statuses

} {endpoints.length > 0 && endpoints.map((endpoint: CachedEndpointStatus) => { const { name, hostname, status } = endpoint; const url = `https://${hostname}`; return (

{name}

{url}

{formatStatus(status)}

); })}
); }