File size: 997 Bytes
d3a497e
 
7ceb966
 
 
c4d103b
 
7ceb966
c4d103b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getApiEndpoint, ApiEndpoints } from "$lib/config";

export const GET = async ({ url }) => {
    const voteType = url.searchParams.get('vote_type') || 'render';
    const apiUrl = `${getApiEndpoint(ApiEndpoints.LEADERBOARD)}?vote_type=${voteType}`;

    try {
        const response = await fetch(apiUrl, {
            method: "GET",
            headers: {
                Authorization: `Bearer ${import.meta.env.VITE_HF_TOKEN}`,
                "Cache-Control": "no-cache",
            },
        });

        if (response.ok) {
            const result = await response.json();
            return new Response(JSON.stringify(result), { status: 200 });
        } else {
            return new Response(JSON.stringify({ error: "Failed to fetch leaderboard." }), {
                status: response.status,
            });
        }
    } catch (error) {
        return new Response(JSON.stringify({ error: "Failed to fetch leaderboard." }), {
            status: 500,
        });
    }
};