even more refactoring

This commit is contained in:
cnachtigall1991
2021-10-15 04:55:46 +02:00
parent f536a0527f
commit b1a9448eb6
6 changed files with 70 additions and 66 deletions

View File

@@ -1,4 +1,6 @@
import axios from "axios";
export const setTitle = (title) => {
document.title = `${title} | csgoWTF`
}
export const GetWinLoss = (matchResult, teamId) => {
if (matchResult === teamId) {
@@ -43,42 +45,3 @@ export const getPlayerArr = (stats, team) => {
return arr
}
export const TrackMe = async (id64, authcode, sharecode) => {
let statusError = ''
let status = 200
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
return [status, statusError]
}
if (authcode === '' || !authCodeRegex.test(authcode)) {
statusError = 'Is not a valid authcode'
status = 418
return [status, statusError]
}
try {
const res = await axios
.post(`${process.env.VUE_APP_API_URL}/player/trackme`, `id=${id64}&authcode=${authcode}&sharecode=${sharecode}`)
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 {
console.log(`${err.response.status}: ${err.response.statusText}`)
}
}
return [status, statusError]
}