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

View File

@ -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">