Initial push

This commit is contained in:
2026-03-08 15:49:34 +01:00
parent 8da12bb7d1
commit 47127f276d
101 changed files with 13844 additions and 8 deletions

View File

@@ -0,0 +1,35 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { fetchVanillaVersions, fetchPaperVersions, fetchFabricVersions, type VersionInfo } from "@/lib/minecraft/versions";
import { checkRateLimit, getClientIp } from "@/lib/security/rateLimit";
export async function GET(req: NextRequest) {
const session = await auth.api.getSession({ headers: req.headers });
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const ip = getClientIp(req);
const { allowed } = checkRateLimit(ip, 20);
if (!allowed) return NextResponse.json({ error: "Too many requests" }, { status: 429 });
const type = req.nextUrl.searchParams.get("type") ?? "vanilla";
try {
let versionInfos: VersionInfo[];
switch (type) {
case "paper":
versionInfos = await fetchPaperVersions();
break;
case "fabric":
versionInfos = await fetchFabricVersions();
break;
case "vanilla":
default:
versionInfos = await fetchVanillaVersions();
}
const versions = versionInfos.map((v) => v.id);
return NextResponse.json({ versions, type });
} catch (err) {
const message = err instanceof Error ? err.message : "Failed to fetch versions";
return NextResponse.json({ error: message }, { status: 503 });
}
}