old stuff
This commit is contained in:
@@ -11,22 +11,19 @@
|
||||
class="navbar-toggler"
|
||||
data-bs-target="#mainNav"
|
||||
data-bs-toggle="collapse"
|
||||
type="button"
|
||||
>
|
||||
type="button">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div
|
||||
id="mainNav"
|
||||
class="collapse navbar-collapse navbar-nav justify-content-between"
|
||||
>
|
||||
class="collapse navbar-collapse navbar-nav justify-content-between">
|
||||
<ul class="list-unstyled">
|
||||
<li class="nav-item">
|
||||
<router-link
|
||||
class="nav-link"
|
||||
to="/matches"
|
||||
@click="closeNav('mainNav')"
|
||||
>
|
||||
@click="closeNav('mainNav')">
|
||||
Matches
|
||||
</router-link>
|
||||
</li>
|
||||
@@ -35,8 +32,7 @@
|
||||
id="search-form"
|
||||
class="d-flex"
|
||||
@keydown.enter.prevent="parseSearch"
|
||||
@submit.prevent="parseSearch"
|
||||
>
|
||||
@submit.prevent="parseSearch">
|
||||
<label for="search">
|
||||
<i class="fa fa-search"></i>
|
||||
</label>
|
||||
@@ -49,14 +45,12 @@
|
||||
class="form-control bg-transparent border-0"
|
||||
placeholder="SteamID, Profile Link or ShareCode"
|
||||
title="SteamID, Profile Link or ShareCode"
|
||||
type="search"
|
||||
/>
|
||||
type="search" />
|
||||
<button
|
||||
id="search-button"
|
||||
class="btn border-2 btn-outline-info"
|
||||
type="button"
|
||||
@click="parseSearch"
|
||||
>
|
||||
@click="parseSearch">
|
||||
Search!
|
||||
</button>
|
||||
</form>
|
||||
@@ -66,7 +60,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive } from "vue";
|
||||
import { reactive } from 'vue'
|
||||
import {
|
||||
closeNav,
|
||||
closeNavEventListener,
|
||||
@@ -77,125 +71,125 @@ import {
|
||||
ParseMatch,
|
||||
parseShareCode,
|
||||
sleep,
|
||||
stringSanitizer,
|
||||
} from "@/utils";
|
||||
stringSanitizer
|
||||
} from '@/utils'
|
||||
import {
|
||||
CUSTOM_URL_BASE,
|
||||
ID64_PATTERN,
|
||||
MATCH_SHARE_URL_BASE,
|
||||
PROFILE_URL_BASE,
|
||||
SHARECODE_REGEX,
|
||||
VANITY_PATTERN,
|
||||
} from "@/constants";
|
||||
import { StatusCodes as STATUS } from "http-status-codes";
|
||||
import { useSearchParamsStore } from "@/stores/searchParams";
|
||||
import type { infoState } from "@/stores/infoState";
|
||||
import { useInfoStateStore } from "@/stores/infoState";
|
||||
import { usePlayerDetailsStore } from "@/stores/playerDetails";
|
||||
VANITY_PATTERN
|
||||
} from '@/constants'
|
||||
import { StatusCodes as STATUS } from 'http-status-codes'
|
||||
import { useSearchParamsStore } from '@/stores/searchParams'
|
||||
import type { infoState } from '@/stores/infoState'
|
||||
import { useInfoStateStore } from '@/stores/infoState'
|
||||
import { usePlayerDetailsStore } from '@/stores/playerDetails'
|
||||
|
||||
const searchParamsStore = useSearchParamsStore();
|
||||
const infoStateStore = useInfoStateStore();
|
||||
const playerDetailsStore = usePlayerDetailsStore();
|
||||
const searchParamsStore = useSearchParamsStore()
|
||||
const infoStateStore = useInfoStateStore()
|
||||
const playerDetailsStore = usePlayerDetailsStore()
|
||||
|
||||
const data = reactive({
|
||||
searchInput: "",
|
||||
});
|
||||
searchInput: ''
|
||||
})
|
||||
|
||||
const parseSearch = async () => {
|
||||
let input = data.searchInput;
|
||||
let input = data.searchInput
|
||||
|
||||
searchParamsStore.$reset();
|
||||
searchParamsStore.$reset()
|
||||
|
||||
if (data.searchInput !== "") {
|
||||
if (data.searchInput !== '') {
|
||||
// remove various base-urls + cut excess parameters
|
||||
input = input
|
||||
.replace(MATCH_SHARE_URL_BASE, "")
|
||||
.replace(CUSTOM_URL_BASE, "")
|
||||
.replace(PROFILE_URL_BASE, "")
|
||||
.split("/")[0]
|
||||
.split("?")[0];
|
||||
.replace(MATCH_SHARE_URL_BASE, '')
|
||||
.replace(CUSTOM_URL_BASE, '')
|
||||
.replace(PROFILE_URL_BASE, '')
|
||||
.split('/')[0]
|
||||
.split('?')[0]
|
||||
|
||||
// process shareCode
|
||||
const tmpShareCode = Array.from(input.matchAll(SHARECODE_REGEX));
|
||||
const inputShareCode = tmpShareCode.length > 0 ? tmpShareCode[0][0] : "";
|
||||
const tmpShareCode = Array.from(input.matchAll(SHARECODE_REGEX))
|
||||
const inputShareCode = tmpShareCode.length > 0 ? tmpShareCode[0][0] : ''
|
||||
searchParamsStore.shareCode = SHARECODE_REGEX.test(inputShareCode)
|
||||
? inputShareCode
|
||||
: "";
|
||||
: ''
|
||||
|
||||
// process id64
|
||||
const tmpId64 = Array.from(input.matchAll(ID64_PATTERN));
|
||||
const inputId64 = tmpId64.length > 0 ? tmpId64[0][0] : "";
|
||||
searchParamsStore.id64 = ID64_PATTERN.test(inputId64) ? inputId64 : "";
|
||||
const tmpId64 = Array.from(input.matchAll(ID64_PATTERN))
|
||||
const inputId64 = tmpId64.length > 0 ? tmpId64[0][0] : ''
|
||||
searchParamsStore.id64 = ID64_PATTERN.test(inputId64) ? inputId64 : ''
|
||||
|
||||
// process vanityUrl
|
||||
if (searchParamsStore.shareCode === "" && searchParamsStore.id64 === "") {
|
||||
if (searchParamsStore.shareCode === '' && searchParamsStore.id64 === '') {
|
||||
if (input.includes(CUSTOM_URL_BASE)) {
|
||||
input = input.replace(CUSTOM_URL_BASE, "");
|
||||
input = input.replace(CUSTOM_URL_BASE, '')
|
||||
}
|
||||
|
||||
if (VANITY_PATTERN.test(input)) {
|
||||
searchParamsStore.vanityUrl = stringSanitizer(input);
|
||||
searchParamsStore.vanityUrl = stringSanitizer(input)
|
||||
} else {
|
||||
const info: infoState = {
|
||||
statusCode: STATUS.NOT_ACCEPTABLE,
|
||||
message:
|
||||
'Only alphanumeric symbols, "_", and "-", between 3-32 characters',
|
||||
type: "warning",
|
||||
};
|
||||
infoStateStore.addInfo(info);
|
||||
type: 'warning'
|
||||
}
|
||||
infoStateStore.addInfo(info)
|
||||
}
|
||||
}
|
||||
|
||||
// GetUser
|
||||
if (searchParamsStore.id64 !== "" || searchParamsStore.vanityUrl !== "") {
|
||||
if (searchParamsStore.id64 !== '' || searchParamsStore.vanityUrl !== '') {
|
||||
const [resData, info] = await GetUser(
|
||||
searchParamsStore.vanityUrl || searchParamsStore.id64
|
||||
);
|
||||
)
|
||||
|
||||
if (info.message !== "") infoStateStore.addInfo(info);
|
||||
if (info.message !== '') infoStateStore.addInfo(info)
|
||||
if (resData !== null) {
|
||||
data.searchInput = "";
|
||||
const activeElem = document.activeElement as HTMLInputElement;
|
||||
activeElem.blur();
|
||||
data.searchInput = ''
|
||||
const activeElem = document.activeElement as HTMLInputElement
|
||||
activeElem.blur()
|
||||
|
||||
playerDetailsStore.playerDetails = resData;
|
||||
playerDetailsStore.playerDetails = resData
|
||||
|
||||
if (searchParamsStore.vanityUrl) {
|
||||
closeNav("mainNav");
|
||||
GoToPlayer(searchParamsStore.vanityUrl);
|
||||
closeNav('mainNav')
|
||||
GoToPlayer(searchParamsStore.vanityUrl)
|
||||
} else if (searchParamsStore.id64) {
|
||||
closeNav("mainNav");
|
||||
GoToPlayer(searchParamsStore.id64);
|
||||
closeNav('mainNav')
|
||||
GoToPlayer(searchParamsStore.id64)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ParseMatch
|
||||
if (searchParamsStore.shareCode !== "") {
|
||||
data.searchInput = "";
|
||||
if (searchParamsStore.shareCode !== '') {
|
||||
data.searchInput = ''
|
||||
|
||||
const matchId = parseShareCode(searchParamsStore.shareCode);
|
||||
let info = await ParseMatch(searchParamsStore.shareCode);
|
||||
const matchId = parseShareCode(searchParamsStore.shareCode)
|
||||
let info = await ParseMatch(searchParamsStore.shareCode)
|
||||
|
||||
if (info.message !== "") infoStateStore.addInfo(info);
|
||||
if (info.statusCode === STATUS.OK) GoToMatch(matchId);
|
||||
if (info.message !== '') infoStateStore.addInfo(info)
|
||||
if (info.statusCode === STATUS.OK) GoToMatch(matchId)
|
||||
|
||||
if (info.statusCode === STATUS.ACCEPTED) {
|
||||
let [res, info] = await GetMatchDetails(matchId);
|
||||
let [res, info] = await GetMatchDetails(matchId)
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (res !== null && res.parsed) break;
|
||||
[res, info] = await GetMatchDetails(matchId);
|
||||
if (res !== null && res.parsed) break
|
||||
;[res, info] = await GetMatchDetails(matchId)
|
||||
|
||||
sleep(2000);
|
||||
sleep(2000)
|
||||
}
|
||||
GoToMatch(matchId);
|
||||
GoToMatch(matchId)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
closeNavEventListener("mainNav");
|
||||
closeNavEventListener('mainNav')
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -272,7 +266,7 @@ nav {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
input[type="search"] {
|
||||
input[type='search'] {
|
||||
min-width: 300px;
|
||||
max-width: 300px;
|
||||
|
||||
@@ -301,7 +295,7 @@ nav {
|
||||
margin-left: auto !important;
|
||||
margin-right: auto !important;
|
||||
|
||||
input[type="search"] {
|
||||
input[type='search'] {
|
||||
margin-left: 0 !important;
|
||||
max-width: 60vw !important;
|
||||
min-width: 60vw !important;
|
||||
@@ -314,7 +308,7 @@ nav {
|
||||
margin-left: auto !important;
|
||||
margin-right: auto !important;
|
||||
|
||||
input[type="search"] {
|
||||
input[type='search'] {
|
||||
margin-left: 0 !important;
|
||||
max-width: 65vw !important;
|
||||
min-width: 65vw !important;
|
||||
@@ -327,7 +321,7 @@ nav {
|
||||
margin-left: auto !important;
|
||||
margin-right: auto !important;
|
||||
|
||||
input[type="search"] {
|
||||
input[type='search'] {
|
||||
margin-left: 0 !important;
|
||||
max-width: 68vw !important;
|
||||
min-width: 68vw !important;
|
||||
@@ -376,7 +370,7 @@ nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
input[type="search"] {
|
||||
input[type='search'] {
|
||||
margin-bottom: 15px;
|
||||
margin-left: 37px;
|
||||
max-width: 400px;
|
||||
|
@@ -1,156 +1,156 @@
|
||||
import axios from "axios";
|
||||
import { StatusCodes as STATUS } from "http-status-codes";
|
||||
import { AUTHCODE_REGEX, SHARECODE_REGEX } from "@/constants";
|
||||
import axios from 'axios'
|
||||
import { StatusCodes as STATUS } from 'http-status-codes'
|
||||
import { AUTHCODE_REGEX, SHARECODE_REGEX } from '@/constants'
|
||||
import type {
|
||||
Match,
|
||||
MatchChat,
|
||||
MatchRounds,
|
||||
MatchWeapons,
|
||||
Player,
|
||||
PlayerMeta,
|
||||
} from "@/types";
|
||||
import type { infoState } from "@/stores/infoState";
|
||||
import { reactive } from "vue";
|
||||
PlayerMeta
|
||||
} from '@/types'
|
||||
import type { infoState } from '@/stores/infoState'
|
||||
import { reactive } from 'vue'
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL;
|
||||
const API_URL = import.meta.env.VITE_API_URL
|
||||
|
||||
// /player/<id> GET returns player <id> details (last 10 matches)
|
||||
export const GetUser = async (
|
||||
id: string
|
||||
): Promise<[Player | null, infoState]> => {
|
||||
let response: Player | null = null;
|
||||
let response: Player | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${id}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Player not found";
|
||||
break;
|
||||
info.message = 'Player not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get meta-stats or player";
|
||||
break;
|
||||
info.message = 'Unable to get meta-stats or player'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /player/<id>/meta/<limit> GET returns player <id> meta-stats with <limit>
|
||||
export const GetPlayerMeta = async (
|
||||
player_id: string,
|
||||
limit = 4
|
||||
): Promise<[PlayerMeta | null, infoState]> => {
|
||||
let response: PlayerMeta | null = null;
|
||||
let response: PlayerMeta | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${player_id}/meta/${limit}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Player not found";
|
||||
break;
|
||||
info.message = 'Player not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get player meta";
|
||||
break;
|
||||
info.message = 'Unable to get player meta'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /player/<id>/next/<unix> GET returns 20 matches after <unix> for player <id>
|
||||
export const LoadMoreMatches = async (
|
||||
player_id: string,
|
||||
date: number
|
||||
): Promise<[Player | null, infoState]> => {
|
||||
let response: Player | null = null;
|
||||
let response: Player | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${player_id}/next/${date}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Player not found";
|
||||
break;
|
||||
info.message = 'Player not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get meta-stats or player";
|
||||
break;
|
||||
info.message = 'Unable to get meta-stats or player'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /player/<id>/track POST Track player <id> FORM_DATA: authcode, [sharecode]
|
||||
export const TrackMe = async (
|
||||
id64: string,
|
||||
authcode: string,
|
||||
sharecode = ""
|
||||
sharecode = ''
|
||||
): Promise<infoState> => {
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
if (sharecode !== "" && !SHARECODE_REGEX.test(sharecode)) {
|
||||
info.statusCode = STATUS.IM_A_TEAPOT;
|
||||
info.message = "Sharecode is invalid";
|
||||
info.type = "error";
|
||||
if (sharecode !== '' && !SHARECODE_REGEX.test(sharecode)) {
|
||||
info.statusCode = STATUS.IM_A_TEAPOT
|
||||
info.message = 'Sharecode is invalid'
|
||||
info.type = 'error'
|
||||
}
|
||||
if (authcode === "" || !AUTHCODE_REGEX.test(authcode.toUpperCase())) {
|
||||
info.statusCode = STATUS.IM_A_TEAPOT;
|
||||
info.message = "Authcode is invalid";
|
||||
info.type = "error";
|
||||
if (authcode === '' || !AUTHCODE_REGEX.test(authcode.toUpperCase())) {
|
||||
info.statusCode = STATUS.IM_A_TEAPOT
|
||||
info.message = 'Authcode is invalid'
|
||||
info.type = 'error'
|
||||
}
|
||||
|
||||
if (info.statusCode === 0 && info.message === "") {
|
||||
if (info.statusCode === 0 && info.message === '') {
|
||||
await axios
|
||||
.post(
|
||||
`${API_URL}/player/${id64}/track`,
|
||||
@@ -158,328 +158,331 @@ export const TrackMe = async (
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.ACCEPTED) {
|
||||
info.statusCode = STATUS.ACCEPTED;
|
||||
info.message = "Tracking successful";
|
||||
info.statusCode = STATUS.ACCEPTED
|
||||
info.message = 'Tracking successful'
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Invalid arguments";
|
||||
break;
|
||||
info.message = 'Invalid arguments'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Player not found";
|
||||
break;
|
||||
info.message = 'Player not found'
|
||||
break
|
||||
case STATUS.SERVICE_UNAVAILABLE:
|
||||
info.message =
|
||||
"Service currently unavailable - Please try again later";
|
||||
break;
|
||||
'Service currently unavailable - Please try again later'
|
||||
break
|
||||
case STATUS.UNAUTHORIZED:
|
||||
info.message = "Authcode is invalid";
|
||||
break;
|
||||
info.message = 'Authcode is invalid'
|
||||
break
|
||||
case STATUS.PRECONDITION_FAILED:
|
||||
info.message = "Sharecode is invalid or missing";
|
||||
break;
|
||||
info.message = 'Sharecode is invalid or missing'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message =
|
||||
"Service is currently unavailable - Please try again later";
|
||||
break;
|
||||
'Service is currently unavailable - Please try again later'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
}
|
||||
return info;
|
||||
};
|
||||
return info
|
||||
}
|
||||
|
||||
// /match/<id> GET returns details for match <id>
|
||||
export const GetMatchDetails = async (
|
||||
match_id: string
|
||||
): Promise<[Match | null, infoState]> => {
|
||||
let response: Match | null = null;
|
||||
let response: Match | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Error parsing matchID";
|
||||
break;
|
||||
info.message = 'Error parsing matchID'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Match not found";
|
||||
break;
|
||||
info.message = 'Match not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get match data";
|
||||
break;
|
||||
info.message = 'Unable to get match data'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /match/<id>/rounds GET returns round-stats for match <id>
|
||||
export const GetPlayerValue = async (
|
||||
match_id: string
|
||||
): Promise<[MatchRounds | null, infoState]> => {
|
||||
let response: MatchRounds | null = null;
|
||||
let response: MatchRounds | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/rounds`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Error parsing matchID";
|
||||
break;
|
||||
info.message = 'Error parsing matchID'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Match not found";
|
||||
break;
|
||||
info.message = 'Match not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get match data";
|
||||
break;
|
||||
info.message = 'Unable to get match data'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /match/<id>/weapons GET returns weapon-stats for match <id>
|
||||
export const GetWeaponDmg = async (
|
||||
match_id: string
|
||||
): Promise<[MatchWeapons | null, infoState]> => {
|
||||
let response: MatchWeapons | null = null;
|
||||
let response: MatchWeapons | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/weapons`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Weapon damage not found";
|
||||
break;
|
||||
info.message = 'Weapon damage not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get weapon damage";
|
||||
break;
|
||||
info.message = 'Unable to get weapon damage'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /match/<id>/chat GET returns chat history for match <id>
|
||||
export const GetChatHistory = async (
|
||||
match_id: string
|
||||
): Promise<[MatchChat | null, infoState]> => {
|
||||
let response: MatchChat | null = null;
|
||||
let response: MatchChat | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/chat`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Weapon damage not found";
|
||||
break;
|
||||
info.message = 'Weapon damage not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get weapon damage";
|
||||
break;
|
||||
info.message = 'Unable to get weapon damage'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /matches/<id>/chat/<langCode> GET returns chat history for match <id> with translated sections
|
||||
export const GetChatHistoryTranslated = async (
|
||||
match_id: string
|
||||
): Promise<[MatchChat | null, infoState]> => {
|
||||
let response: MatchChat | null = null;
|
||||
let response: MatchChat | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/chat?translate=1`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
info.message = "Chat was not found";
|
||||
break;
|
||||
info.message = 'Chat was not found'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to get chat";
|
||||
break;
|
||||
info.message = 'Unable to get chat'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /matches GET returns last 20 matches in DB
|
||||
export const GetMatches = async (): Promise<[Match[] | null, infoState]> => {
|
||||
let response: Match[] | null = null;
|
||||
let response: Match[] | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/matches`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to marshal JSON";
|
||||
break;
|
||||
info.message = 'Unable to marshal JSON'
|
||||
break
|
||||
case STATUS.FORBIDDEN:
|
||||
info.message = 'Forbidden'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
return [response, info];
|
||||
};
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /matches/next/<unix> GET returns 20 matches after time <unix>
|
||||
export const LoadMoreMatchesExplore = async (
|
||||
date: number
|
||||
): Promise<[Match[] | null, infoState]> => {
|
||||
let response: Match[] | null = null;
|
||||
let response: Match[] | null = null
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/matches/next/${date}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK) response = res.data;
|
||||
if (res.status === STATUS.OK) response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
info.message = "Unable to load more matches";
|
||||
break;
|
||||
info.message = 'Unable to load more matches'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return [response, info];
|
||||
};
|
||||
return [response, info]
|
||||
}
|
||||
|
||||
// /match/parse/<shareCode>
|
||||
export const ParseMatch = async (shareCode: string): Promise<infoState> => {
|
||||
const info = reactive<infoState>({
|
||||
statusCode: 0,
|
||||
message: "",
|
||||
type: "success",
|
||||
});
|
||||
message: '',
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/parse/${shareCode}`)
|
||||
.then((res) => {
|
||||
switch (res.status) {
|
||||
case STATUS.OK:
|
||||
info.statusCode = STATUS.OK;
|
||||
info.message = "";
|
||||
break;
|
||||
info.statusCode = STATUS.OK
|
||||
info.message = ''
|
||||
break
|
||||
case STATUS.ACCEPTED:
|
||||
info.statusCode = STATUS.ACCEPTED;
|
||||
info.message = "Match will be parsed";
|
||||
break;
|
||||
info.statusCode = STATUS.ACCEPTED
|
||||
info.message = 'Match will be parsed'
|
||||
break
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
info.message = "Bad request";
|
||||
break;
|
||||
info.message = 'Bad request'
|
||||
break
|
||||
case STATUS.SERVICE_UNAVAILABLE:
|
||||
info.message = "Unable to parse match";
|
||||
break;
|
||||
info.message = 'Unable to parse match'
|
||||
break
|
||||
default:
|
||||
info.message = "An unknown error occurred";
|
||||
info.message = 'An unknown error occurred'
|
||||
}
|
||||
info.statusCode = err.response.status;
|
||||
info.type = "error";
|
||||
});
|
||||
info.statusCode = err.response.status
|
||||
info.type = 'error'
|
||||
})
|
||||
|
||||
return info;
|
||||
};
|
||||
return info
|
||||
}
|
||||
|
Reference in New Issue
Block a user