added option for impact route to return a specific map with ?mapName parameter

This commit is contained in:
jenz
2026-10-04 16:30:53 +02:00
parent 8a76454784
commit 7a6051987e
2 changed files with 31 additions and 4 deletions
@@ -8,6 +8,17 @@ export async function GET(req: NextRequest) {
const directionParam = req.nextUrl.searchParams.get('direction');
const offset = Math.max(0, Number(req.nextUrl.searchParams.get('offset')) || 0);
// Accept either `mapName=foo` or `mapNames=foo,bar` (also tolerate
// repeated `mapName` params), so individual maps can be looked up
// directly instead of paging through the whole leaderboard.
const mapNames = [
...req.nextUrl.searchParams.getAll('mapName'),
...req.nextUrl.searchParams.getAll('mapNames'),
]
.flatMap((v) => v.split(','))
.map((v) => v.trim())
.filter(Boolean);
const sortBy = sortByParam === 'popularity' ? 'popularity' : 'impact';
// Impact defaults to ascending (worst/most population-harming first, the
// whole point of the feature); popularity defaults to descending (most
@@ -16,8 +27,15 @@ export async function GET(req: NextRequest) {
? directionParam
: sortBy === 'popularity' ? 'desc' : 'asc';
const maps = await getMapImpactLeaderboard(sortBy, direction, PAGE_SIZE, offset);
const hasMore = maps.length === PAGE_SIZE;
const maps = await getMapImpactLeaderboard(
sortBy,
direction,
PAGE_SIZE,
offset,
mapNames.length > 0 ? mapNames : undefined,
);
// Pagination only applies when not filtering by name (see getMapImpactLeaderboard).
const hasMore = mapNames.length === 0 && maps.length === PAGE_SIZE;
return NextResponse.json({ maps, hasMore });
}