updated api requests from try/catch to axios handling
All checks were successful
CSGOWTF/csgowtf/pipeline/head This commit looks good
All checks were successful
CSGOWTF/csgowtf/pipeline/head This commit looks good
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"dotenv-webpack": "^7.1.0",
|
||||
"echarts": "^5.3.0",
|
||||
"fork-awesome": "^1.2.0",
|
||||
"http-status-codes": "^2.2.0",
|
||||
"jquery": "^3.6.0",
|
||||
"luxon": "^2.3.0",
|
||||
"string-sanitizer": "^2.0.2",
|
||||
|
@@ -21,3 +21,6 @@ export const GRENADES = {
|
||||
|
||||
export const NAV_HEIGHT = 70
|
||||
export const FOOTER_HEIGHT = 200
|
||||
|
||||
export const SHARECODE_REGEX = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/
|
||||
export const AUTHCODE_REGEX = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/
|
||||
|
@@ -1,171 +1,310 @@
|
||||
import axios from "axios";
|
||||
import {errorHandling} from "@/utils/Utils";
|
||||
import {StatusCodes as STATUS} from "http-status-codes";
|
||||
import {AUTHCODE_REGEX, SHARECODE_REGEX} from "@/constants";
|
||||
|
||||
const API_URL = process.env.VUE_APP_API_URL
|
||||
// const TIMEOUT = 10_000
|
||||
|
||||
export const GetMatches = async () => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/matches`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/matches`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - bad request')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200)
|
||||
return res.data
|
||||
} catch {
|
||||
console.log('Could not load matches')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const GetUser = async (id) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/player/${id}`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${id}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200)
|
||||
return res.data
|
||||
} catch {
|
||||
console.log('Could not load user')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const TrackMe = async (id64, authcode, sharecode = '') => {
|
||||
let statusError = ''
|
||||
// TODO: NEEDS WORK!!!!!
|
||||
|
||||
let statusError = null
|
||||
let status = 202
|
||||
|
||||
const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/
|
||||
const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/
|
||||
|
||||
if (sharecode !== '' && !shareCodeRegex.test(sharecode)) {
|
||||
statusError = 'Is not a valid sharecode'
|
||||
status = 418
|
||||
if (sharecode !== '' && !SHARECODE_REGEX.test(sharecode)) {
|
||||
statusError = 'Sharecode is invalid or missing'
|
||||
status = STATUS.IM_A_TEAPOT
|
||||
return [status, statusError]
|
||||
}
|
||||
if (authcode === '' || !authCodeRegex.test(authcode)) {
|
||||
statusError = 'Is not a valid authcode'
|
||||
status = 418
|
||||
if (authcode === '' || !AUTHCODE_REGEX.test(authcode)) {
|
||||
statusError = 'Authcode is invalid or missing'
|
||||
status = STATUS.IM_A_TEAPOT
|
||||
return [status, statusError]
|
||||
}
|
||||
|
||||
try {
|
||||
// const res = await axios
|
||||
// .post(`${API_URL}/player/${id64}/track`, `authcode=${authcode}&sharecode=${sharecode}`)
|
||||
|
||||
// TODO: Needs testing
|
||||
|
||||
const res = await axios({
|
||||
method: 'post',
|
||||
await axios
|
||||
.post({
|
||||
url: `${API_URL}/player/${id64}/track`,
|
||||
data: `authcode=${authcode}&sharecode=${sharecode}`,
|
||||
data: `authcode=${authcode}&sharecode=${sharecode}`
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.ACCEPTED)
|
||||
status = res.status
|
||||
})
|
||||
.catch((err) => {
|
||||
status = err.response.status
|
||||
|
||||
if (res.status === 202) {
|
||||
status = res.status
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.response.status === 401) {
|
||||
statusError = 'Data does not match player'
|
||||
status = err.response.status
|
||||
} else if (err.response.status === 400) {
|
||||
statusError = 'Userinput was wrong'
|
||||
status = err.response.status
|
||||
} else {
|
||||
errorHandling(err.response.status)
|
||||
}
|
||||
}
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
statusError = 'Invalid arguments'
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
statusError = 'Player not found'
|
||||
break
|
||||
case STATUS.SERVICE_UNAVAILABLE:
|
||||
statusError = 'Problem with request'
|
||||
break
|
||||
case STATUS.UNAUTHORIZED:
|
||||
statusError = 'Authcode is invalid'
|
||||
break
|
||||
case STATUS.PRECONDITION_FAILED:
|
||||
statusError = 'Sharecode is invalid or missing'
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
statusError = 'Service currently unavailable - please try again later'
|
||||
break
|
||||
default:
|
||||
statusError = 'An unknown error occured'
|
||||
console.log('TrackMe - An unknown error occured')
|
||||
}
|
||||
})
|
||||
|
||||
return [status, statusError]
|
||||
}
|
||||
|
||||
export const GetPlayerValue = async (match_id) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/match/${match_id}/rounds`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/rounds`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerValue - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerValue - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerValue - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerValue - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not get player value')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const GetMatchDetails = async (match_id) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/match/${match_id}`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatchDetails - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatchDetails - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatchDetails - internal server errror')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatchDetails - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not load match details')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const LoadMoreMatches = async (player_id, date) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/player/${player_id}/next/${date}`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${player_id}/next/${date}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetUser - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not load more matches')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const GetPlayerMeta = async (player_id, limit = 4) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/player/${player_id}/meta/${limit}`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/player/${player_id}/meta/${limit}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerMeta - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerMeta - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerMeta - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetPlayerMeta - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not load player metadata')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const GetWeaponDmg = async (match_id) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/match/${match_id}/weapons`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/match/${match_id}/weapons`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetWeaponDmg - bad request')
|
||||
break
|
||||
case STATUS.NOT_FOUND:
|
||||
// TODO: ERROR
|
||||
console.log('GetWeaponDmg - not found')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetWeaponDmg - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetWeaponDmg - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not calculate weapon damage')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export const LoadMoreMatchesExplore = async (date) => {
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: `${API_URL}/matches/next/${date}`,
|
||||
let response = null
|
||||
|
||||
await axios
|
||||
.get(`${API_URL}/matches/next/${date}`)
|
||||
.then((res) => {
|
||||
if (res.status === STATUS.OK)
|
||||
response = res.data
|
||||
})
|
||||
.catch((err) => {
|
||||
switch (err.response.status) {
|
||||
case STATUS.BAD_REQUEST:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - bad request')
|
||||
break
|
||||
case STATUS.INTERNAL_SERVER_ERROR:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - internal server error')
|
||||
break
|
||||
default:
|
||||
// TODO: ERROR
|
||||
console.log('GetMatches - default error')
|
||||
}
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data
|
||||
}
|
||||
} catch {
|
||||
console.log('Could not load more matches')
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
@@ -4047,6 +4047,7 @@ __metadata:
|
||||
eslint: ^6.8.0
|
||||
eslint-plugin-vue: ^7.20.0
|
||||
fork-awesome: ^1.2.0
|
||||
http-status-codes: ^2.2.0
|
||||
jquery: ^3.6.0
|
||||
luxon: ^2.3.0
|
||||
sass: ^1.49.0
|
||||
@@ -6338,6 +6339,13 @@ fsevents@~2.3.2:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"http-status-codes@npm:^2.2.0":
|
||||
version: 2.2.0
|
||||
resolution: "http-status-codes@npm:2.2.0"
|
||||
checksum: 31e1d730856210445da0907d9b484629e69e4fe92ac032478a7aa4d89e5b215e2b4e75d7ebce40d0537b6850bd281b2f65c7cc36cc2677e5de056d6cea1045ce
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"https-browserify@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "https-browserify@npm:1.0.0"
|
||||
|
Reference in New Issue
Block a user