forked from CSGOWTF/csgowtf
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
import axios from "axios";
|
|
|
|
const API_URL = process.env.VUE_APP_API_URL
|
|
|
|
|
|
export const GetUser = async (id) => {
|
|
try {
|
|
const res = await axios.get(`${API_URL}/player/${id}`)
|
|
|
|
if (res.status === 200)
|
|
return [res.status, res.data]
|
|
} catch (err) {
|
|
if (err.response)
|
|
return [err.response.status, err.response.statusText]
|
|
}
|
|
}
|
|
|
|
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)) {
|
|
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(`${API_URL}/player/${id64}/track`, `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]
|
|
}
|