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