From 6ef42703d88e74799a44968c9cf1d82b4dec039e Mon Sep 17 00:00:00 2001 From: Nino K Date: Fri, 20 Sep 2024 08:07:24 +0300 Subject: [PATCH] oops i forgot --- .../misc/minecraftSkin/[username]/route.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/app/api/data/misc/minecraftSkin/[username]/route.ts diff --git a/src/app/api/data/misc/minecraftSkin/[username]/route.ts b/src/app/api/data/misc/minecraftSkin/[username]/route.ts new file mode 100644 index 0000000..2f96022 --- /dev/null +++ b/src/app/api/data/misc/minecraftSkin/[username]/route.ts @@ -0,0 +1,39 @@ +export async function GET( + request: Request, + { params }: { params: { username: string } } + ) { + const username = params.username + // Helper function to fetch the Mojang profile ID based on the username + async function getProfileId(username: string): Promise { + const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`); + if (response.ok) { + const data = await response.json(); + return data.id; + } + return null; + } + + // Helper function to fetch the session profile and decode the skin URL + async function getSkinUrl(profileId: string): Promise { + const response = await fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${profileId}`); + if (response.ok) { + const data = await response.json(); + const properties = data.properties.find((prop: any) => prop.name === "textures"); + if (properties) { + const decoded = JSON.parse(atob(properties.value)); + return decoded.textures.SKIN.url; + } + } + return null; + } + + try { + const profileId = await getProfileId(username); + if (profileId) { + const skinUrl = await getSkinUrl(profileId); + return Response.json(skinUrl); + } + } catch (error) { + return Response.json("Failed to fetch skin URL:" + error); + } +} \ No newline at end of file