cleanup
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 57s

This commit is contained in:
Lee 2024-04-16 23:49:00 +01:00
parent 3faf706f82
commit 0678c38bfe
2 changed files with 36 additions and 21 deletions

@ -18,16 +18,10 @@ type Params = {
}; };
export async function generateMetadata({ params: { id } }: Params): Promise<Metadata> { export async function generateMetadata({ params: { id } }: Params): Promise<Metadata> {
let error: string | undefined = undefined; const { error, player } = await fetchPlayer(id);
let player: Player | undefined = undefined;
try {
player = (await getData(id))?.player;
} catch (err) {
error = (err as McUtilsAPIError).message;
}
if (error && player == undefined) { if (error && player == undefined) {
return generateEmbed({ title: "Unknown Player", description: "Invalid UUID / Username" }); return generateEmbed({ title: "Unknown Player", description: error });
} }
const { username, uniqueId, skin } = player as Player; const { username, uniqueId, skin } = player as Player;
@ -54,16 +48,28 @@ async function getData(id: string): Promise<CachedPlayer | null> {
return await getPlayer(id); return await getPlayer(id);
} }
export default async function Page({ params }: Params): Promise<JSX.Element> { /**
* Fetches the player's data from the uuid or username
*
* @param id the player's uuid or username
* @returns the player's data or an error message
*/
async function fetchPlayer(id: string): Promise<{ error: string | undefined; player: Player | undefined }> {
let error: string | undefined = undefined; let error: string | undefined = undefined;
let player: Player | undefined = undefined; let player: Player | undefined = undefined;
try { try {
player = (await getData(params.id))?.player; player = (await getData(id))?.player;
} catch (err) { } catch (err) {
error = (err as McUtilsAPIError).message; error = (err as McUtilsAPIError).message;
} }
return { error, player };
}
export default async function Page({ params: { id } }: Params): Promise<JSX.Element> {
const { error, player } = await fetchPlayer(id);
return ( return (
<div className="h-full flex flex-col items-center"> <div className="h-full flex flex-col items-center">
<div className="mb-4 text-center"> <div className="mb-4 text-center">

@ -20,17 +20,10 @@ type Params = {
}; };
export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> { export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> {
let error: string | undefined = undefined; const { error, server } = await fetchServer(platform, hostname);
let server: JavaMinecraftServer | BedrockMinecraftServer | undefined = undefined;
try {
server = (await getServer(platform, hostname))?.server;
} catch (err) {
error = (err as McUtilsAPIError).message;
}
if (error && server == undefined) { if (error && server == undefined) {
return generateEmbed({ title: "Unknown Server", description: "Server not responding" }); return generateEmbed({ title: "Unknown Server", description: error });
} }
const { hostname: serverHostname, players } = server as JavaMinecraftServer | BedrockMinecraftServer; const { hostname: serverHostname, players } = server as JavaMinecraftServer | BedrockMinecraftServer;
@ -69,16 +62,32 @@ async function getData(
return (await getServer(platform, hostname)).server; return (await getServer(platform, hostname)).server;
} }
export default async function Page({ params: { platform, hostname } }: Params): Promise<JSX.Element> { /**
* Fetches the server's data from the hostname
*
* @param platform the server's platform
* @param hostname the server's hostname
* @returns the server's data or an error message
*/
async function fetchServer(
platform: ServerPlatform,
hostname: string
): Promise<{ error: string | undefined; server: JavaMinecraftServer | BedrockMinecraftServer | undefined }> {
let error: string | undefined = undefined; let error: string | undefined = undefined;
let server: JavaMinecraftServer | BedrockMinecraftServer | undefined = undefined; let server: JavaMinecraftServer | BedrockMinecraftServer | undefined = undefined;
try { try {
server = (await getServer(platform, hostname))?.server; server = (await getData(platform, hostname)) as JavaMinecraftServer | BedrockMinecraftServer;
} catch (err) { } catch (err) {
error = (err as McUtilsAPIError).message; error = (err as McUtilsAPIError).message;
} }
return { error, server };
}
export default async function Page({ params: { platform, hostname } }: Params): Promise<JSX.Element> {
const { error, server } = await fetchServer(platform, hostname);
let favicon = null; // Server favicon let favicon = null; // Server favicon
// Java specific // Java specific