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> {
let error: string | undefined = undefined;
let player: Player | undefined = undefined;
const { error, player } = await fetchPlayer(id);
try {
player = (await getData(id))?.player;
} catch (err) {
error = (err as McUtilsAPIError).message;
}
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;
@ -54,16 +48,28 @@ async function getData(id: string): Promise<CachedPlayer | null> {
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 player: Player | undefined = undefined;
try {
player = (await getData(params.id))?.player;
player = (await getData(id))?.player;
} catch (err) {
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 (
<div className="h-full flex flex-col items-center">
<div className="mb-4 text-center">

@ -20,17 +20,10 @@ type Params = {
};
export async function generateMetadata({ params: { platform, hostname } }: Params): Promise<Metadata> {
let error: string | undefined = undefined;
let server: JavaMinecraftServer | BedrockMinecraftServer | undefined = undefined;
try {
server = (await getServer(platform, hostname))?.server;
} catch (err) {
error = (err as McUtilsAPIError).message;
}
const { error, server } = await fetchServer(platform, hostname);
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;
@ -69,16 +62,32 @@ async function getData(
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 server: JavaMinecraftServer | BedrockMinecraftServer | undefined = undefined;
try {
server = (await getServer(platform, hostname))?.server;
server = (await getData(platform, hostname)) as JavaMinecraftServer | BedrockMinecraftServer;
} catch (err) {
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
// Java specific