37 lines
873 B
TypeScript
37 lines
873 B
TypeScript
import "server-only";
|
|
import { admin, required } from "./supabase";
|
|
import type {
|
|
LeaderboardData,
|
|
LeaderboardDifficulty,
|
|
} from "@/shared/leaderboard";
|
|
|
|
export async function leaderboard({
|
|
difficulty = "all",
|
|
search = "",
|
|
page = 1,
|
|
limit = 25,
|
|
}: {
|
|
difficulty?: LeaderboardDifficulty;
|
|
search?: string;
|
|
page?: number;
|
|
limit?: number;
|
|
} = {}): Promise<LeaderboardData | null> {
|
|
try {
|
|
return required(
|
|
await admin().rpc("player_leaderboard", {
|
|
p_difficulty: difficulty,
|
|
p_search: search,
|
|
p_page: page,
|
|
p_limit: limit,
|
|
}),
|
|
) as unknown as LeaderboardData;
|
|
} catch (error) {
|
|
// A leaderboard outage must not take the map catalog or homepage offline.
|
|
console.error(
|
|
"Leaderboard query failed",
|
|
error instanceof Error ? error.message : "Unknown error",
|
|
);
|
|
return null;
|
|
}
|
|
}
|