forked from CSGOWTF/csgowtf
added api util functions
This commit is contained in:
@@ -15,14 +15,14 @@ export const GetUser = async (id) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const TrackMe = async (id64, authcode, sharecode) => {
|
||||
export const TrackMe = async (id64, authcode, sharecode = '') => {
|
||||
let statusError = ''
|
||||
let status = 202
|
||||
|
||||
const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/
|
||||
const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/
|
||||
|
||||
if (sharecode && !shareCodeRegex.test(sharecode)) {
|
||||
if (sharecode !== '' && !shareCodeRegex.test(sharecode)) {
|
||||
statusError = 'Is not a valid sharecode'
|
||||
status = 418
|
||||
return [status, statusError]
|
||||
@@ -67,9 +67,35 @@ export const getPlayerValue = async (match_id) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const loadMoreMatches = async (player_id, date) => {
|
||||
export const getMatchDetails = async (match_id) => {
|
||||
try {
|
||||
const res = await axios.get(`${API_URL}/player/${player_id}/after/${date}`)
|
||||
const res = await axios.get(`${API_URL}/match/${match_id}`)
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
}
|
||||
}
|
||||
|
||||
export const loadMoreMatches = async (player_id, date) => {
|
||||
try {
|
||||
const res = await axios.get(`${API_URL}/player/${player_id}/next/${date}`)
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: 400, 404
|
||||
console.log(err.response.status, err.response.statusText)
|
||||
}
|
||||
}
|
||||
|
||||
export const getPlayerMeta = async (player_id, limit = 4) => {
|
||||
try {
|
||||
const res = await axios.get(`${API_URL}/player/${player_id}/meta/${limit}`)
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
|
||||
@@ -3,7 +3,7 @@ import {GoToLink, GoToMatch, GoToPlayer} from "./GoTo";
|
||||
import {SaveLastVisitedToLocalStorage} from "./LocalStorage";
|
||||
import {GetHLTV_1} from "./HLTV";
|
||||
import {DisplayRank, LoadImage} from "./Display";
|
||||
import {GetUser, TrackMe, getPlayerValue, loadMoreMatches} from "./ApiRequests";
|
||||
import {GetUser, TrackMe, getPlayerValue, loadMoreMatches, getPlayerMeta, getMatchDetails} from "./ApiRequests";
|
||||
import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav} from "./Utils";
|
||||
|
||||
export {
|
||||
@@ -12,6 +12,6 @@ export {
|
||||
SaveLastVisitedToLocalStorage,
|
||||
GetHLTV_1,
|
||||
DisplayRank, LoadImage,
|
||||
GetUser, TrackMe, getPlayerValue, loadMoreMatches,
|
||||
GetUser, TrackMe, getPlayerValue, loadMoreMatches, getPlayerMeta, getMatchDetails,
|
||||
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user