import { NextRequest, NextResponse } from "next/server"; import { minecraft } from "@/lib/servertap"; import { cfg } from "@/lib/cfg"; export async function POST(req: NextRequest) { const key = req.headers.get("authorization") ?? ""; if (cfg.minecraftApi.key && key !== `Bearer ${cfg.minecraftApi.key}`) return NextResponse.json({ error: "unauthorized" }, { status: 401 }); const { event, javaUuid, bedrockXuid, bedrockName } = await req.json(); // Transfer entitlement: query current LP groups via RCON and re-apply if (event === "link" && javaUuid && bedrockXuid) { const r: any = await minecraft.executeCommand(`lp user ${bedrockName ?? bedrockXuid} parent info`); const m = String(r?.data?.response ?? ""); const group = m.match(/(\b(?:iron|gold|diamond|patron)\b)/)?.[1]; if (group) { await minecraft.grantTier(javaUuid, group); await minecraft.removeTier(`.${bedrockName ?? ""}`.replace("..", "."), group).catch(() => {}); } } if (event === "unlink" && javaUuid && bedrockXuid) { // optionally revoke from bedrock counterpart } return NextResponse.json({ ok: true }); }