39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const xuid = req.nextUrl.searchParams.get("xuid");
|
|
if (!xuid) return NextResponse.json({ error: "missing xuid" }, { status: 400 });
|
|
try {
|
|
const r = await fetch(`https://api.geysermc.org/v2/skin/${encodeURIComponent(xuid)}`, {
|
|
headers: { "User-Agent": "frg-web/1.0" },
|
|
next: { revalidate: 3600 },
|
|
});
|
|
if (r.ok) {
|
|
const j = await r.json();
|
|
if (j.texture_id) {
|
|
return NextResponse.json({
|
|
textureId: j.texture_id as string,
|
|
textureUrl: `https://textures.minecraft.net/texture/${j.texture_id}`,
|
|
source: "geyser",
|
|
});
|
|
}
|
|
}
|
|
// 503 / no skin cached — fall through to Floodgate UUID fallback
|
|
// Floodgate UUID is 00000000-0000-0000-<hex(xuid) padded to 16>
|
|
const hex = BigInt(xuid).toString(16).padStart(16, "0");
|
|
const floodgateUuid = `00000000-0000-0000-${hex.slice(0, 4)}-${hex.slice(4)}`;
|
|
return NextResponse.json({
|
|
textureId: null,
|
|
textureUrl: null,
|
|
fallbackUuid: floodgateUuid,
|
|
// mc-heads and crafatar both serve skins by UUID (Floodgate skins via Geyser's upload)
|
|
fallbackUrls: [
|
|
`https://mc-heads.net/skin/${floodgateUuid}`,
|
|
`https://crafatar.com/skins/${floodgateUuid}`,
|
|
],
|
|
geyserStatus: r.status,
|
|
});
|
|
} catch (e) {
|
|
return NextResponse.json({ error: String(e) }, { status: 500 });
|
|
}
|
|
}
|