This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user