even more refactoring ✨
This commit is contained in:
@@ -1,19 +1,56 @@
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = process.env.VUE_APP_API_URL
|
||||
|
||||
|
||||
export const GetUser = async (id) => {
|
||||
try {
|
||||
const res = await axios.get(`${process.env.VUE_APP_API_URL}/player/${id}`)
|
||||
const res = await axios.get(`${API_URL}/player/${id}`)
|
||||
|
||||
if (res.status === 200) {
|
||||
return [200, res.data]
|
||||
}
|
||||
if (res.status === 200)
|
||||
return [res.status, res.data]
|
||||
} catch (err) {
|
||||
if (err.response) {
|
||||
if (err.response.status === 404) {
|
||||
return [404, 'Player not found']
|
||||
}
|
||||
} else {
|
||||
console.log(err.response)
|
||||
}
|
||||
if (err.response.status === 404)
|
||||
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(`${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]
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import router from "../router";
|
||||
|
||||
export const GoToMatch = (id) => {
|
||||
router.push({name: 'Match', params: {match_id: id}})
|
||||
router.push({name: 'Match', params: {match_id: id}})
|
||||
}
|
||||
|
||||
export const GoToPlayer = (id) => {
|
||||
router.push({name: 'Player', params: {id: id}})
|
||||
router.push({name: 'Player', params: {id: id}})
|
||||
}
|
||||
|
||||
export const GoToLink = (link) => {
|
||||
router.push(`${link}`)
|
||||
router.push(link)
|
||||
}
|
||||
|
@@ -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]
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@ import {GoToLink, GoToMatch, GoToPlayer} from "./GoTo";
|
||||
import {SaveLastVisitedToLocalStorage} from "./LocalStorage";
|
||||
import {GetHLTV_1} from "./HLTV";
|
||||
import {DisplayRank, LoadImage} from "./Display";
|
||||
import {GetUser} from "./ApiRequests";
|
||||
import {GetWinLoss, TrackMe, truncate, checkStatEmpty, getPlayerArr} from "./Utils";
|
||||
import {GetUser, TrackMe} from "./ApiRequests";
|
||||
import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr} from "./Utils";
|
||||
|
||||
export {
|
||||
FormatDate, FormatFullDuration, FormatFullDate, FormatDuration,
|
||||
@@ -12,6 +12,6 @@ export {
|
||||
SaveLastVisitedToLocalStorage,
|
||||
GetHLTV_1,
|
||||
DisplayRank, LoadImage,
|
||||
GetUser,
|
||||
GetWinLoss, TrackMe, truncate, checkStatEmpty, getPlayerArr
|
||||
GetUser, TrackMe,
|
||||
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr
|
||||
}
|
||||
|
@@ -41,13 +41,13 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {GoToPlayer, SaveLastVisitedToLocalStorage} from "../utils";
|
||||
import {GoToPlayer, SaveLastVisitedToLocalStorage, setTitle} from "../utils";
|
||||
import {onBeforeMount, ref} from "vue";
|
||||
|
||||
export default {
|
||||
name: 'Home',
|
||||
setup() {
|
||||
document.title = 'Home | csgoWTF'
|
||||
setTitle('Home')
|
||||
|
||||
const recentVisited = ref([])
|
||||
|
||||
|
@@ -201,8 +201,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {onMounted, reactive} from "vue";
|
||||
import router from "../router";
|
||||
import {onMounted, reactive, watch} from "vue";
|
||||
import {useStore} from "vuex";
|
||||
import {
|
||||
DisplayRank,
|
||||
@@ -216,7 +215,7 @@ import {
|
||||
GoToLink,
|
||||
GoToMatch,
|
||||
LoadImage,
|
||||
SaveLastVisitedToLocalStorage,
|
||||
SaveLastVisitedToLocalStorage, setTitle,
|
||||
TrackMe
|
||||
} from "../utils";
|
||||
|
||||
@@ -245,8 +244,8 @@ export default {
|
||||
})
|
||||
|
||||
const GetPlayer = async () => {
|
||||
if (router.currentRoute.value.params.id) {
|
||||
const [res, resData] = await GetUser(router.currentRoute.value.params.id)
|
||||
if (props.id) {
|
||||
const [res, resData] = await GetUser(props.id)
|
||||
|
||||
if (res === 200 && resData) {
|
||||
data.playerDetails = resData
|
||||
@@ -267,7 +266,7 @@ export default {
|
||||
}
|
||||
SaveLastVisitedToLocalStorage(player)
|
||||
|
||||
document.title = `${data.playerDetails.name} | csgoWTF`
|
||||
setTitle(data.playerDetails.name)
|
||||
|
||||
console.log(data.playerDetails)
|
||||
} else {
|
||||
@@ -286,6 +285,11 @@ export default {
|
||||
data.statusErrorCode = 0
|
||||
data.statusError = ''
|
||||
data.tracked = true
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
data.statusError = ''
|
||||
data.statusErrorCode = 0
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user