aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/utils/scoreUpload.ts
blob: 7fa7c86676b70ce23f73e61a84c5c15e95bb657b (plain) (blame)
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
31
32
33
34
35
36
37
38
39
interface UploadScoreData {
  meta: {
    game: string;
    service: string;
    playtype: string;
  };
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  scores: any[];
}

interface UploadScoreResponse {
  scoreCount: number;
  message?: string;
}

export async function uploadScore(data: UploadScoreData): Promise<UploadScoreResponse> {
  const response = await fetch(`${import.meta.env.VITE_API_URL}/uploadScore`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    credentials: 'include',
    body: JSON.stringify({
      meta: {
        game: data.meta.game,
        service: data.meta.service,
        playtype: data.meta.playtype
      },
      scores: data.scores
    })
  });

  if (!response.ok) {
    const errorData = await response.json();
    throw new Error(errorData.error || 'Failed to upload scores');
  }

  return response.json();
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage