aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/api
diff options
context:
space:
mode:
authorFifthWit <fifthwitbusiness@gmail.com>2025-01-30 10:44:30 -0600
committerFifthWit <fifthwitbusiness@gmail.com>2025-01-30 10:44:30 -0600
commite40f07211f5f15dcb138e2520a76d13afd3c0cfd (patch)
tree46bad6a17e66d55a4a65088c0b6eb8c48641615a /frontend/src/api
parentadded prettier for more consistency (diff)
downloadlphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.tar.gz
lphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.tar.bz2
lphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.zip
formatted with prettier
Diffstat (limited to 'frontend/src/api')
-rw-r--r--frontend/src/api/Api.ts18
-rw-r--r--frontend/src/api/Auth.ts8
-rw-r--r--frontend/src/api/Games.ts28
-rw-r--r--frontend/src/api/Maps.ts160
-rw-r--r--frontend/src/api/Mod.ts104
-rw-r--r--frontend/src/api/Rankings.ts6
-rw-r--r--frontend/src/api/User.ts6
7 files changed, 211 insertions, 119 deletions
diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts
index 0e1658c..b98dda3 100644
--- a/frontend/src/api/Api.ts
+++ b/frontend/src/api/Api.ts
@@ -1,14 +1,14 @@
1import { MapDiscussionContent, ModMenuContent } from "@customTypes/Content"; 1import { MapDiscussionContent, ModMenuContent } from '@customTypes/Content';
2import { delete_token, get_token } from "@api/Auth"; 2import { delete_token, get_token } from '@api/Auth';
3import { get_user, get_profile, post_profile } from "@api/User"; 3import { get_user, get_profile, post_profile } from '@api/User';
4import { 4import {
5 get_games, 5 get_games,
6 get_chapters, 6 get_chapters,
7 get_games_chapters, 7 get_games_chapters,
8 get_game_maps, 8 get_game_maps,
9 get_search, 9 get_search,
10} from "@api/Games"; 10} from '@api/Games';
11import { get_official_rankings, get_unofficial_rankings } from "@api/Rankings"; 11import { get_official_rankings, get_unofficial_rankings } from '@api/Rankings';
12import { 12import {
13 get_map_summary, 13 get_map_summary,
14 get_map_leaderboard, 14 get_map_leaderboard,
@@ -19,14 +19,14 @@ import {
19 delete_map_discussion, 19 delete_map_discussion,
20 post_record, 20 post_record,
21 delete_map_record, 21 delete_map_record,
22} from "@api/Maps"; 22} from '@api/Maps';
23import { 23import {
24 delete_map_summary, 24 delete_map_summary,
25 post_map_summary, 25 post_map_summary,
26 put_map_image, 26 put_map_image,
27 put_map_summary, 27 put_map_summary,
28} from "@api/Mod"; 28} from '@api/Mod';
29import { UploadRunContent } from "@customTypes/Content"; 29import { UploadRunContent } from '@customTypes/Content';
30 30
31// add new api call function entries here 31// add new api call function entries here
32// example usage: API.get_games(); 32// example usage: API.get_games();
@@ -91,7 +91,7 @@ export const API = {
91 delete_map_summary(token, map_id, route_id), 91 delete_map_summary(token, map_id, route_id),
92}; 92};
93 93
94const BASE_API_URL: string = "/api/v1/"; 94const BASE_API_URL: string = '/api/v1/';
95 95
96export function url(path: string): string { 96export function url(path: string): string {
97 return BASE_API_URL + path; 97 return BASE_API_URL + path;
diff --git a/frontend/src/api/Auth.ts b/frontend/src/api/Auth.ts
index 875c7e5..e495d47 100644
--- a/frontend/src/api/Auth.ts
+++ b/frontend/src/api/Auth.ts
@@ -1,8 +1,8 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3 3
4export const get_token = async (): Promise<string | undefined> => { 4export const get_token = async (): Promise<string | undefined> => {
5 const response = await axios.get(url(`token`)) 5 const response = await axios.get(url(`token`));
6 if (!response.data.success) { 6 if (!response.data.success) {
7 return undefined; 7 return undefined;
8 } 8 }
@@ -10,5 +10,5 @@ export const get_token = async (): Promise<string | undefined> => {
10}; 10};
11 11
12export const delete_token = async () => { 12export const delete_token = async () => {
13 await axios.delete(url("token")); 13 await axios.delete(url('token'));
14}; 14};
diff --git a/frontend/src/api/Games.ts b/frontend/src/api/Games.ts
index 72bb4b3..0e47091 100644
--- a/frontend/src/api/Games.ts
+++ b/frontend/src/api/Games.ts
@@ -1,31 +1,35 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3import { GameChapter, GamesChapters } from "@customTypes/Chapters"; 3import { GameChapter, GamesChapters } from '@customTypes/Chapters';
4import { Game } from "@customTypes/Game"; 4import { Game } from '@customTypes/Game';
5import { Map } from "@customTypes/Map"; 5import { Map } from '@customTypes/Map';
6import { Search } from "@customTypes/Search"; 6import { Search } from '@customTypes/Search';
7 7
8export const get_games = async (): Promise<Game[]> => { 8export const get_games = async (): Promise<Game[]> => {
9 const response = await axios.get(url(`games`)) 9 const response = await axios.get(url(`games`));
10 return response.data.data; 10 return response.data.data;
11}; 11};
12 12
13export const get_chapters = async (chapter_id: string): Promise<GameChapter> => { 13export const get_chapters = async (
14 chapter_id: string
15): Promise<GameChapter> => {
14 const response = await axios.get(url(`chapters/${chapter_id}`)); 16 const response = await axios.get(url(`chapters/${chapter_id}`));
15 return response.data.data; 17 return response.data.data;
16} 18};
17 19
18export const get_games_chapters = async (game_id: string): Promise<GamesChapters> => { 20export const get_games_chapters = async (
21 game_id: string
22): Promise<GamesChapters> => {
19 const response = await axios.get(url(`games/${game_id}`)); 23 const response = await axios.get(url(`games/${game_id}`));
20 return response.data.data; 24 return response.data.data;
21}; 25};
22 26
23export const get_game_maps = async (game_id: string): Promise<Map[]> => { 27export const get_game_maps = async (game_id: string): Promise<Map[]> => {
24 const response = await axios.get(url(`games/${game_id}/maps`)) 28 const response = await axios.get(url(`games/${game_id}/maps`));
25 return response.data.data.maps; 29 return response.data.data.maps;
26}; 30};
27 31
28export const get_search = async (q: string): Promise<Search> => { 32export const get_search = async (q: string): Promise<Search> => {
29 const response = await axios.get(url(`search?q=${q}`)) 33 const response = await axios.get(url(`search?q=${q}`));
30 return response.data.data; 34 return response.data.data;
31}; 35};
diff --git a/frontend/src/api/Maps.ts b/frontend/src/api/Maps.ts
index aa967ce..3a22f88 100644
--- a/frontend/src/api/Maps.ts
+++ b/frontend/src/api/Maps.ts
@@ -1,15 +1,25 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3import { MapDiscussionContent, UploadRunContent } from "@customTypes/Content"; 3import { MapDiscussionContent, UploadRunContent } from '@customTypes/Content';
4import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "@customTypes/Map"; 4import {
5 MapSummary,
6 MapLeaderboard,
7 MapDiscussions,
8 MapDiscussion,
9} from '@customTypes/Map';
5 10
6export const get_map_summary = async (map_id: string): Promise<MapSummary> => { 11export const get_map_summary = async (map_id: string): Promise<MapSummary> => {
7 const response = await axios.get(url(`maps/${map_id}/summary`)) 12 const response = await axios.get(url(`maps/${map_id}/summary`));
8 return response.data.data; 13 return response.data.data;
9}; 14};
10 15
11export const get_map_leaderboard = async (map_id: string, page: string): Promise<MapLeaderboard | undefined> => { 16export const get_map_leaderboard = async (
12 const response = await axios.get(url(`maps/${map_id}/leaderboards?page=${page}`)); 17 map_id: string,
18 page: string
19): Promise<MapLeaderboard | undefined> => {
20 const response = await axios.get(
21 url(`maps/${map_id}/leaderboards?page=${page}`)
22 );
13 if (!response.data.success) { 23 if (!response.data.success) {
14 return undefined; 24 return undefined;
15 } 25 }
@@ -25,7 +35,9 @@ export const get_map_leaderboard = async (map_id: string, page: string): Promise
25 return data; 35 return data;
26}; 36};
27 37
28export const get_map_discussions = async (map_id: string): Promise<MapDiscussions | undefined> => { 38export const get_map_discussions = async (
39 map_id: string
40): Promise<MapDiscussions | undefined> => {
29 const response = await axios.get(url(`maps/${map_id}/discussions`)); 41 const response = await axios.get(url(`maps/${map_id}/discussions`));
30 if (!response.data.data.discussions) { 42 if (!response.data.data.discussions) {
31 return undefined; 43 return undefined;
@@ -33,74 +45,122 @@ export const get_map_discussions = async (map_id: string): Promise<MapDiscussion
33 return response.data.data; 45 return response.data.data;
34}; 46};
35 47
36export const get_map_discussion = async (map_id: string, discussion_id: number): Promise<MapDiscussion | undefined> => { 48export const get_map_discussion = async (
37 const response = await axios.get(url(`maps/${map_id}/discussions/${discussion_id}`)); 49 map_id: string,
50 discussion_id: number
51): Promise<MapDiscussion | undefined> => {
52 const response = await axios.get(
53 url(`maps/${map_id}/discussions/${discussion_id}`)
54 );
38 if (!response.data.data.discussion) { 55 if (!response.data.data.discussion) {
39 return undefined; 56 return undefined;
40 } 57 }
41 return response.data.data; 58 return response.data.data;
42}; 59};
43 60
44export const post_map_discussion = async (token: string, map_id: string, content: MapDiscussionContent): Promise<boolean> => { 61export const post_map_discussion = async (
45 const response = await axios.post(url(`maps/${map_id}/discussions`), { 62 token: string,
46 "title": content.title, 63 map_id: string,
47 "content": content.content, 64 content: MapDiscussionContent
48 }, { 65): Promise<boolean> => {
49 headers: { 66 const response = await axios.post(
50 "Authorization": token, 67 url(`maps/${map_id}/discussions`),
68 {
69 title: content.title,
70 content: content.content,
71 },
72 {
73 headers: {
74 Authorization: token,
75 },
51 } 76 }
52 }); 77 );
53 return response.data.success; 78 return response.data.success;
54}; 79};
55 80
56export const post_map_discussion_comment = async (token: string, map_id: string, discussion_id: number, comment: string): Promise<boolean> => { 81export const post_map_discussion_comment = async (
57 const response = await axios.post(url(`maps/${map_id}/discussions/${discussion_id}`), { 82 token: string,
58 "comment": comment, 83 map_id: string,
59 }, { 84 discussion_id: number,
60 headers: { 85 comment: string
61 "Authorization": token, 86): Promise<boolean> => {
87 const response = await axios.post(
88 url(`maps/${map_id}/discussions/${discussion_id}`),
89 {
90 comment: comment,
91 },
92 {
93 headers: {
94 Authorization: token,
95 },
62 } 96 }
63 }); 97 );
64 return response.data.success; 98 return response.data.success;
65}; 99};
66 100
67export const delete_map_discussion = async (token: string, map_id: string, discussion_id: number): Promise<boolean> => { 101export const delete_map_discussion = async (
68 const response = await axios.delete(url(`maps/${map_id}/discussions/${discussion_id}`), { 102 token: string,
69 headers: { 103 map_id: string,
70 "Authorization": token, 104 discussion_id: number
105): Promise<boolean> => {
106 const response = await axios.delete(
107 url(`maps/${map_id}/discussions/${discussion_id}`),
108 {
109 headers: {
110 Authorization: token,
111 },
71 } 112 }
72 }); 113 );
73 return response.data.success; 114 return response.data.success;
74}; 115};
75 116
76export const post_record = async (token: string, run: UploadRunContent, map_id: number): Promise<[boolean, string]> => { 117export const post_record = async (
118 token: string,
119 run: UploadRunContent,
120 map_id: number
121): Promise<[boolean, string]> => {
77 if (run.partner_demo) { 122 if (run.partner_demo) {
78 const response = await axios.postForm(url(`maps/${map_id}/record`), { 123 const response = await axios.postForm(
79 "host_demo": run.host_demo, 124 url(`maps/${map_id}/record`),
80 "partner_demo": run.partner_demo, 125 {
81 }, { 126 host_demo: run.host_demo,
82 headers: { 127 partner_demo: run.partner_demo,
83 "Authorization": token, 128 },
129 {
130 headers: {
131 Authorization: token,
132 },
84 } 133 }
85 }); 134 );
86 return [response.data.success, response.data.message]; 135 return [response.data.success, response.data.message];
87 } else { 136 } else {
88 const response = await axios.postForm(url(`maps/${map_id}/record`), { 137 const response = await axios.postForm(
89 "host_demo": run.host_demo, 138 url(`maps/${map_id}/record`),
90 }, { 139 {
91 headers: { 140 host_demo: run.host_demo,
92 "Authorization": token, 141 },
142 {
143 headers: {
144 Authorization: token,
145 },
93 } 146 }
94 }); 147 );
95 return [response.data.success, response.data.message]; 148 return [response.data.success, response.data.message];
96 } 149 }
97} 150};
98 151
99export const delete_map_record = async (token: string, map_id: number, record_id: number): Promise<boolean> => { 152export const delete_map_record = async (
100 const response = await axios.delete(url(`maps/${map_id}/record/${record_id}`), { 153 token: string,
101 headers: { 154 map_id: number,
102 "Authorization": token, 155 record_id: number
156): Promise<boolean> => {
157 const response = await axios.delete(
158 url(`maps/${map_id}/record/${record_id}`),
159 {
160 headers: {
161 Authorization: token,
162 },
103 } 163 }
104 }); 164 );
105 return response.data.success; 165 return response.data.success;
106}; 166};
diff --git a/frontend/src/api/Mod.ts b/frontend/src/api/Mod.ts
index 1511f8b..69e76c5 100644
--- a/frontend/src/api/Mod.ts
+++ b/frontend/src/api/Mod.ts
@@ -1,58 +1,86 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3import { ModMenuContent } from "@customTypes/Content"; 3import { ModMenuContent } from '@customTypes/Content';
4 4
5export const put_map_image = async (token: string, map_id: string, image: string): Promise<boolean> => { 5export const put_map_image = async (
6 const response = await axios.put(url(`maps/${map_id}/image`), { 6 token: string,
7 "image": image, 7 map_id: string,
8 }, { 8 image: string
9 headers: { 9): Promise<boolean> => {
10 "Authorization": token, 10 const response = await axios.put(
11 url(`maps/${map_id}/image`),
12 {
13 image: image,
14 },
15 {
16 headers: {
17 Authorization: token,
18 },
11 } 19 }
12 }); 20 );
13 return response.data.success; 21 return response.data.success;
14}; 22};
15 23
16export const post_map_summary = async (token: string, map_id: string, content: ModMenuContent): Promise<boolean> => { 24export const post_map_summary = async (
17 const response = await axios.post(url(`maps/${map_id}/summary`), { 25 token: string,
18 "category_id": content.category_id, 26 map_id: string,
19 "user_name": content.name, 27 content: ModMenuContent
20 "score_count": content.score, 28): Promise<boolean> => {
21 "record_date": content.date, 29 const response = await axios.post(
22 "showcase": content.showcase, 30 url(`maps/${map_id}/summary`),
23 "description": content.description, 31 {
24 }, { 32 category_id: content.category_id,
25 headers: { 33 user_name: content.name,
26 "Authorization": token, 34 score_count: content.score,
35 record_date: content.date,
36 showcase: content.showcase,
37 description: content.description,
38 },
39 {
40 headers: {
41 Authorization: token,
42 },
27 } 43 }
28 }); 44 );
29 return response.data.success; 45 return response.data.success;
30}; 46};
31 47
32export const put_map_summary = async (token: string, map_id: string, content: ModMenuContent): Promise<boolean> => { 48export const put_map_summary = async (
33 const response = await axios.put(url(`maps/${map_id}/summary`), { 49 token: string,
34 "route_id": content.id, 50 map_id: string,
35 "user_name": content.name, 51 content: ModMenuContent
36 "score_count": content.score, 52): Promise<boolean> => {
37 "record_date": content.date, 53 const response = await axios.put(
38 "showcase": content.showcase, 54 url(`maps/${map_id}/summary`),
39 "description": content.description, 55 {
40 }, { 56 route_id: content.id,
41 headers: { 57 user_name: content.name,
42 "Authorization": token, 58 score_count: content.score,
59 record_date: content.date,
60 showcase: content.showcase,
61 description: content.description,
62 },
63 {
64 headers: {
65 Authorization: token,
66 },
43 } 67 }
44 }); 68 );
45 return response.data.success; 69 return response.data.success;
46}; 70};
47 71
48export const delete_map_summary = async (token: string, map_id: string, route_id: number): Promise<boolean> => { 72export const delete_map_summary = async (
73 token: string,
74 map_id: string,
75 route_id: number
76): Promise<boolean> => {
49 const response = await axios.delete(url(`maps/${map_id}/summary`), { 77 const response = await axios.delete(url(`maps/${map_id}/summary`), {
50 data: { 78 data: {
51 "route_id": route_id, 79 route_id: route_id,
52 }, 80 },
53 headers: { 81 headers: {
54 "Authorization": token, 82 Authorization: token,
55 } 83 },
56 }); 84 });
57 return response.data.success; 85 return response.data.success;
58}; 86};
diff --git a/frontend/src/api/Rankings.ts b/frontend/src/api/Rankings.ts
index b8d9bec..9afd999 100644
--- a/frontend/src/api/Rankings.ts
+++ b/frontend/src/api/Rankings.ts
@@ -1,6 +1,6 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3import { Ranking, SteamRanking } from "@customTypes/Ranking"; 3import { Ranking, SteamRanking } from '@customTypes/Ranking';
4 4
5export const get_official_rankings = async (): Promise<Ranking> => { 5export const get_official_rankings = async (): Promise<Ranking> => {
6 const response = await axios.get(url(`rankings/lphub`)); 6 const response = await axios.get(url(`rankings/lphub`));
diff --git a/frontend/src/api/User.ts b/frontend/src/api/User.ts
index 004aa22..4ce21e1 100644
--- a/frontend/src/api/User.ts
+++ b/frontend/src/api/User.ts
@@ -1,6 +1,6 @@
1import axios from "axios"; 1import axios from 'axios';
2import { url } from "@api/Api"; 2import { url } from '@api/Api';
3import { UserProfile } from "@customTypes/Profile"; 3import { UserProfile } from '@customTypes/Profile';
4 4
5export const get_user = async (user_id: string): Promise<UserProfile> => { 5export const get_user = async (user_id: string): Promise<UserProfile> => {
6 const response = await axios.get(url(`users/${user_id}`)); 6 const response = await axios.get(url(`users/${user_id}`));