import { bankProfile } from '$lib/server/fleet/bank.js'; import { error } from '@sveltejs/kit'; import { playerReport } from '$lib/server/reports/index.js'; import { isLeaderboardMetric } from '$lib/server/fleet/leaderboard.js'; import { leaderboardReturnHref } from '$lib/leaderboard-navigation.js'; import type { LeaderboardPlayerCount } from '$lib/leaderboard.js'; export async function load({ params, url }: { params: { guid: string }; url: URL }) { const game = url.searchParams.get('game'); const map = url.searchParams.get('map'); const requestedMetric = url.searchParams.get('metric'); const players = url.searchParams.get('players'); if ( (game !== null && game !== 't5' && game !== 't6') || (map !== null && map.length > 1024) || (requestedMetric !== null && !isLeaderboardMetric(requestedMetric)) || (players !== null && !/^[1-4]$/.test(players)) ) { error( 400, 'Use game t5 or t6, a supported metric, players 1–4, and a map key up to 1024 characters.' ); } const metric = requestedMetric !== null && isLeaderboardMetric(requestedMetric) ? requestedMetric : 'highestRound'; const options = { game: game || undefined, map: map || undefined, players: players === null ? undefined : (Number(players) as LeaderboardPlayerCount), metric }; const { profile, entry } = await playerReport( params.guid, Number(url.searchParams.get('offset') ?? 0), options ); if (!profile) error(404, 'Player not found'); return { profile, bank: bankProfile(params.guid), returnTo: leaderboardReturnHref(url.searchParams.get('returnTo')), scope: { game: game ?? '', map: map ?? '', players: players ?? '', metric, entry } }; }