Add player leaderboard and homepage preview
This commit is contained in:
36
lib/leaderboard.ts
Normal file
36
lib/leaderboard.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user