31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { minecraftApi } from "@/lib/minecraft-api";
|
|
import { minecraft } from "@/lib/servertap";
|
|
import { TIERS } from "@/lib/donations";
|
|
|
|
type Platform = "java" | "bedrock";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const username = req.nextUrl.searchParams.get("username")?.trim();
|
|
if (!username || username.length < 3) return NextResponse.json({ error: "username required" }, { status: 400 });
|
|
const platformParam = req.nextUrl.searchParams.get("platform");
|
|
const platforms: Platform[] = platformParam === "java" || platformParam === "bedrock" ? [platformParam] : ["java", "bedrock"];
|
|
try {
|
|
for (const platform of platforms) {
|
|
const resolved = await minecraftApi.resolvePlayerIdentifier({ type: platform, username }).catch(() => null);
|
|
if (!resolved) continue;
|
|
const current = await minecraft.getHighestTierFor({
|
|
platform, username: resolved.username, uuid: resolved.uuid, xuid: resolved.xuid,
|
|
}).catch(() => null);
|
|
if (!current) continue;
|
|
const from = (TIERS as any)[current];
|
|
return NextResponse.json({
|
|
current, label: from?.label ?? current, price: from?.price ?? null,
|
|
platform, resolvedName: resolved.username,
|
|
});
|
|
}
|
|
return NextResponse.json({ current: null, price: null });
|
|
} catch (e: any) {
|
|
return NextResponse.json({ error: e?.message || "lookup failed" }, { status: 500 });
|
|
}
|
|
}
|