Focus player records and add squad leaderboards

This commit is contained in:
2026-10-07 19:14:33 -04:00
parent bab78038dc
commit bcecc42dd1
22 changed files with 569 additions and 430 deletions
@@ -2,19 +2,23 @@ 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))) {
error(400, 'Use game t5 or t6, a supported metric, and a map key up to 1024 characters.');
|| (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, metric };
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, 'No recorded stats found for this player');
return { profile, returnTo: leaderboardReturnHref(url.searchParams.get('returnTo')),
scope: { game: game ?? '', map: map ?? '', metric, entry } };
scope: { game: game ?? '', map: map ?? '', players: players ?? '', metric, entry } };
}