Default leaderboard to all maps
This commit is contained in:
@@ -1,26 +1,9 @@
|
||||
import { GET } from '../api/leaderboard/+server.js';
|
||||
import { error, redirect } from '@sveltejs/kit';
|
||||
import type { LeaderboardPlayerCount, LeaderboardResponse } from '$lib/leaderboard.js';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { LeaderboardResponse } from '$lib/leaderboard.js';
|
||||
import { leaderboardPageSize } from '$lib/leaderboard-updates.js';
|
||||
import { defaultLeaderboardMap } from '$lib/server/fleet/leaderboard.js';
|
||||
|
||||
export async function load({ url }: { url: URL }) {
|
||||
// A present empty map is the explicit All maps view. The API remains
|
||||
// unfiltered by default for callers such as global player search.
|
||||
if (!url.searchParams.has('map')) {
|
||||
const game = url.searchParams.get('game');
|
||||
const players = url.searchParams.get('players');
|
||||
if (game !== null && game !== 't5' && game !== 't6' || players !== null && !/^[1-4]$/.test(players)) {
|
||||
error(400, 'Use game t5 or t6 and players 1–4.');
|
||||
}
|
||||
const map = defaultLeaderboardMap({ game: game ?? undefined, players: players === null ? undefined : Number(players) as LeaderboardPlayerCount });
|
||||
if (map) {
|
||||
const destination = new URL(url);
|
||||
destination.searchParams.set('map', map);
|
||||
destination.searchParams.delete('offset');
|
||||
redirect(307, destination.pathname + destination.search);
|
||||
}
|
||||
}
|
||||
const reportUrl = new URL(url);
|
||||
reportUrl.searchParams.set('limit', String(leaderboardPageSize));
|
||||
const response = await GET({ url: reportUrl });
|
||||
|
||||
Reference in New Issue
Block a user