Skip to content

Commit

Permalink
feat: add playback get route (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangmy21 authored May 8, 2024
1 parent c730aa4 commit d9826e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 15 additions & 7 deletions src/helpers/hasura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export const get_player_code: any = async (team_id: string, player_label: string


/**
* query roound info from round_id
* query round info from round_id
* @param {string} round_id
* @returns {object} {contest_id, map_id}
*/
Expand Down Expand Up @@ -666,28 +666,36 @@ export const get_map_name: any = async (map_id: string) => {
}

/**
* get contest_name by room_id
* get room_info by room_id
* @param {uuid} room_id
* @returns {string} contest_name
* @returns {object} {contest_name, round_id}
*/
export const get_contest_name_by_room: any = async (room_id: string) => {
const query_contest_name = await client.request(
export const get_room_info: any = async (room_id: string) => {
const query_room_info = await client.request(
gql`
query get_contest_name($room_id: uuid!) {
query get_room_info($room_id: uuid!) {
contest_room(where: {room_id: {_eq: $room_id}}) {
contest {
name
}
round_id
}
}
`,
{
room_id: room_id
}
);
return query_contest_name.contest_room[0]?.contest?.name ?? null;
return {
contest_name: query_room_info.contest_room[0]?.contest?.name ?? null,
round_id: query_room_info.contest_room[0]?.round_id ?? null
}
}

/**
* get round_id by room_id
*/

/**
============================================================================
============================ INSERT FUNCTIONS ==============================
Expand Down
2 changes: 1 addition & 1 deletion src/routes/arena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ router.get("/playback", async (req, res) => {
try {
const room_id = req.body.room_id;

const contest_name = await hasura.get_contest_name_by_room(room_id);
const { contest_name } = await hasura.get_room_info(room_id);
const base_directory = await utils.get_base_directory();
const playbackLocalPath = `${base_directory}/temp/${room_id}/playback.thuaipb`;
const playbackCOSPath = `${contest_name}/arena/${room_id}/playback.thuaipb`;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,10 @@ router.get("/playback", async (req, res) => {
try {
const room_id = req.body.room_id;

const contest_name = await hasura.get_contest_name_by_room(room_id);
const { contest_name, round_id } = await hasura.get_room_info(room_id);
const base_directory = await utils.get_base_directory();
const playbackLocalPath = `${base_directory}/temp/${room_id}/playback.thuaipb`;
const playbackCOSPath = `${contest_name}/competition/${room_id}/playback.thuaipb`;
const playbackCOSPath = `${contest_name}/competition/${round_id}/${room_id}/playback.thuaipb`;

const cos = await utils.initCOS();
const config = await utils.getConfig();
Expand Down

0 comments on commit d9826e0

Please sign in to comment.