diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-16 21:13:54 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-10-16 21:13:54 +0300 |
| commit | 92447e02e5fc3977c9cfbca7a8de4132cbb4f13b (patch) | |
| tree | 43a0ecda9c2eaeaf5af39df97ab4ad5083459c2b /frontend/src/api | |
| parent | refactor: upload run dialog (diff) | |
| download | lphub-92447e02e5fc3977c9cfbca7a8de4132cbb4f13b.tar.gz lphub-92447e02e5fc3977c9cfbca7a8de4132cbb4f13b.tar.bz2 lphub-92447e02e5fc3977c9cfbca7a8de4132cbb4f13b.zip | |
refactor: upload run logic improvement
Diffstat (limited to 'frontend/src/api')
| -rw-r--r-- | frontend/src/api/Api.tsx | 4 | ||||
| -rw-r--r-- | frontend/src/api/Maps.tsx | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/frontend/src/api/Api.tsx b/frontend/src/api/Api.tsx index 6731cb3..0f0c4d3 100644 --- a/frontend/src/api/Api.tsx +++ b/frontend/src/api/Api.tsx | |||
| @@ -3,8 +3,9 @@ import { delete_token, get_token } from './Auth'; | |||
| 3 | import { get_user, get_profile, post_profile } from './User'; | 3 | import { get_user, get_profile, post_profile } from './User'; |
| 4 | import { get_games, get_chapters, get_games_chapters, get_game_maps, get_search } from './Games'; | 4 | import { get_games, get_chapters, get_games_chapters, get_game_maps, get_search } from './Games'; |
| 5 | import { get_official_rankings, get_unofficial_rankings } from './Rankings'; | 5 | import { get_official_rankings, get_unofficial_rankings } from './Rankings'; |
| 6 | import { get_map_summary, get_map_leaderboard, get_map_discussions, get_map_discussion, post_map_discussion, post_map_discussion_comment, delete_map_discussion } from './Maps'; | 6 | import { get_map_summary, get_map_leaderboard, get_map_discussions, get_map_discussion, post_map_discussion, post_map_discussion_comment, delete_map_discussion, post_record } from './Maps'; |
| 7 | import { delete_map_summary, post_map_summary, put_map_image, put_map_summary } from './Mod'; | 7 | import { delete_map_summary, post_map_summary, put_map_image, put_map_summary } from './Mod'; |
| 8 | import { UploadRunContent } from '../types/Content'; | ||
| 8 | 9 | ||
| 9 | // add new api call function entries here | 10 | // add new api call function entries here |
| 10 | // example usage: API.get_games(); | 11 | // example usage: API.get_games(); |
| @@ -34,6 +35,7 @@ export const API = { | |||
| 34 | 35 | ||
| 35 | post_map_discussion: (token: string, map_id: string, content: MapDiscussionContent) => post_map_discussion(token, map_id, content), | 36 | post_map_discussion: (token: string, map_id: string, content: MapDiscussionContent) => post_map_discussion(token, map_id, content), |
| 36 | post_map_discussion_comment: (token: string, map_id: string, discussion_id: number, comment: string) => post_map_discussion_comment(token, map_id, discussion_id, comment), | 37 | post_map_discussion_comment: (token: string, map_id: string, discussion_id: number, comment: string) => post_map_discussion_comment(token, map_id, discussion_id, comment), |
| 38 | post_record: (token: string, run: UploadRunContent) => post_record(token, run), | ||
| 37 | 39 | ||
| 38 | delete_map_discussion: (token: string, map_id: string, discussion_id: number) => delete_map_discussion(token, map_id, discussion_id), | 40 | delete_map_discussion: (token: string, map_id: string, discussion_id: number) => delete_map_discussion(token, map_id, discussion_id), |
| 39 | // Mod | 41 | // Mod |
diff --git a/frontend/src/api/Maps.tsx b/frontend/src/api/Maps.tsx index fbad78c..6bdc3e6 100644 --- a/frontend/src/api/Maps.tsx +++ b/frontend/src/api/Maps.tsx | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | import axios from "axios"; | 1 | import axios from "axios"; |
| 2 | import { url } from "./Api"; | 2 | import { url } from "./Api"; |
| 3 | import { MapDiscussionContent } from "../types/Content"; | 3 | import { MapDiscussionContent, UploadRunContent } from "../types/Content"; |
| 4 | import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "../types/Map"; | 4 | import { MapSummary, MapLeaderboard, MapDiscussions, MapDiscussion } from "../types/Map"; |
| 5 | 5 | ||
| 6 | export const get_map_summary = async (map_id: string): Promise<MapSummary> => { | 6 | export const get_map_summary = async (map_id: string): Promise<MapSummary> => { |
| @@ -74,3 +74,27 @@ export const delete_map_discussion = async (token: string, map_id: string, discu | |||
| 74 | }); | 74 | }); |
| 75 | return response.data.success; | 75 | return response.data.success; |
| 76 | }; | 76 | }; |
| 77 | |||
| 78 | export const post_record = async (token: string, run: UploadRunContent): Promise<[string]> => { | ||
| 79 | if (run.partner_demo && run.partner_id) { | ||
| 80 | const response = await axios.postForm(url(`maps/${run.map_id}/record`), { | ||
| 81 | "host_demo": run.host_demo, | ||
| 82 | "partner_demo": run.partner_demo, | ||
| 83 | "partner_id": run.partner_id, | ||
| 84 | }, { | ||
| 85 | headers: { | ||
| 86 | "Authorization": token, | ||
| 87 | } | ||
| 88 | }); | ||
| 89 | return response.data.message; | ||
| 90 | } else { | ||
| 91 | const response = await axios.postForm(url(`maps/${run.map_id}/record`), { | ||
| 92 | "host_demo": run.host_demo, | ||
| 93 | }, { | ||
| 94 | headers: { | ||
| 95 | "Authorization": token, | ||
| 96 | } | ||
| 97 | }); | ||
| 98 | return response.data.message; | ||
| 99 | } | ||
| 100 | }; | ||