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 statusError = ''
|
||||||
let status = 202
|
let status = 202
|
||||||
|
|
||||||
const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/
|
const shareCodeRegex = /^CSGO(?:-?[ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789]{5}){5}$/
|
||||||
const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/
|
const authCodeRegex = /^[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{5}-[ABCDEFGHJKLMNOPQRSTUVWXYZ23456789]{4}$/
|
||||||
|
|
||||||
if (sharecode && !shareCodeRegex.test(sharecode)) {
|
if (sharecode !== '' && !shareCodeRegex.test(sharecode)) {
|
||||||
statusError = 'Is not a valid sharecode'
|
statusError = 'Is not a valid sharecode'
|
||||||
status = 418
|
status = 418
|
||||||
return [status, statusError]
|
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 {
|
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) {
|
if (res.status === 200) {
|
||||||
return res.data
|
return res.data
|
||||||
|
@@ -3,7 +3,7 @@ import {GoToLink, GoToMatch, GoToPlayer} from "./GoTo";
|
|||||||
import {SaveLastVisitedToLocalStorage} from "./LocalStorage";
|
import {SaveLastVisitedToLocalStorage} from "./LocalStorage";
|
||||||
import {GetHLTV_1} from "./HLTV";
|
import {GetHLTV_1} from "./HLTV";
|
||||||
import {DisplayRank, LoadImage} from "./Display";
|
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";
|
import {setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav} from "./Utils";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -12,6 +12,6 @@ export {
|
|||||||
SaveLastVisitedToLocalStorage,
|
SaveLastVisitedToLocalStorage,
|
||||||
GetHLTV_1,
|
GetHLTV_1,
|
||||||
DisplayRank, LoadImage,
|
DisplayRank, LoadImage,
|
||||||
GetUser, TrackMe, getPlayerValue, loadMoreMatches,
|
GetUser, TrackMe, getPlayerValue, loadMoreMatches, getPlayerMeta, getMatchDetails,
|
||||||
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav
|
setTitle, GetWinLoss, truncate, checkStatEmpty, getPlayerArr, constructAvatarUrl, GetAvgRank, FixMapName, closeNav
|
||||||
}
|
}
|
||||||
|
@@ -122,7 +122,8 @@ import {
|
|||||||
FormatFullDate,
|
FormatFullDate,
|
||||||
GetAvgRank,
|
GetAvgRank,
|
||||||
GoToLink,
|
GoToLink,
|
||||||
LoadImage
|
LoadImage,
|
||||||
|
getMatchDetails
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import {useStore} from "vuex";
|
import {useStore} from "vuex";
|
||||||
import {useRoute} from 'vue-router'
|
import {useRoute} from 'vue-router'
|
||||||
@@ -146,19 +147,19 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
const GetMatch = () => {
|
const GetMatch = async () => {
|
||||||
if (matchIdPattern.test(props.match_id))
|
let res = {}
|
||||||
axios
|
if (matchIdPattern.test(props.match_id)) {
|
||||||
.get(`${process.env.VUE_APP_API_URL}/match/${props.match_id}`)
|
res = await getMatchDetails(props.match_id)
|
||||||
.then((response) => {
|
|
||||||
if (response.data.map)
|
if (res.map)
|
||||||
document.title = `${FixMapName(response.data.map)} | csgoWTF`
|
document.title = `${FixMapName(res.map)} | csgoWTF`
|
||||||
else
|
else
|
||||||
document.title = `Match-Details | csgoWTF`
|
document.title = `Match-Details | csgoWTF`
|
||||||
|
|
||||||
store.commit({
|
store.commit({
|
||||||
type: 'changeMatchDetails',
|
type: 'changeMatchDetails',
|
||||||
data: response.data
|
data: res
|
||||||
})
|
})
|
||||||
|
|
||||||
data.matchDetails = store.state.matchDetails
|
data.matchDetails = store.state.matchDetails
|
||||||
@@ -170,12 +171,7 @@ export default {
|
|||||||
data.avgRank = GetAvgRank(data.stats)
|
data.avgRank = GetAvgRank(data.stats)
|
||||||
|
|
||||||
console.log(data.matchDetails)
|
console.log(data.matchDetails)
|
||||||
})
|
} else {
|
||||||
.catch((e) => {
|
|
||||||
console.log(e)
|
|
||||||
// TODO: needs 404
|
|
||||||
})
|
|
||||||
else {
|
|
||||||
console.log('Match not found')
|
console.log('Match not found')
|
||||||
// TODO: needs 404
|
// TODO: needs 404
|
||||||
}
|
}
|
||||||
|
@@ -222,10 +222,9 @@
|
|||||||
<li>Mate 2</li>
|
<li>Mate 2</li>
|
||||||
<li>Mate 3</li>
|
<li>Mate 3</li>
|
||||||
<li>Mate 4</li>
|
<li>Mate 4</li>
|
||||||
<li>Mate 5</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="side-info-box best-mate">
|
<div class="side-info-box most-played-with">
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<h5>Most played with</h5>
|
<h5>Most played with</h5>
|
||||||
</div>
|
</div>
|
||||||
@@ -235,10 +234,9 @@
|
|||||||
<li>Player 2</li>
|
<li>Player 2</li>
|
||||||
<li>Player 3</li>
|
<li>Player 3</li>
|
||||||
<li>Player 4</li>
|
<li>Player 4</li>
|
||||||
<li>Player 5</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="side-info-box best-mate">
|
<div class="side-info-box preferred-weapons">
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<h5>Preferred Weapons</h5>
|
<h5>Preferred Weapons</h5>
|
||||||
</div>
|
</div>
|
||||||
@@ -248,7 +246,18 @@
|
|||||||
<li>Weapon 2</li>
|
<li>Weapon 2</li>
|
||||||
<li>Weapon 3</li>
|
<li>Weapon 3</li>
|
||||||
<li>Weapon 4</li>
|
<li>Weapon 4</li>
|
||||||
<li>Weapon 5</li>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="side-info-box best-map">
|
||||||
|
<div class="heading">
|
||||||
|
<h5>Best Map</h5>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li>Map 1</li>
|
||||||
|
<li>Map 2</li>
|
||||||
|
<li>Map 3</li>
|
||||||
|
<li>Map 4</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -595,7 +604,10 @@ export default {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.best-mate {
|
.best-mate,
|
||||||
|
.preferred-weapons,
|
||||||
|
.most-played-with,
|
||||||
|
.best-map {
|
||||||
.heading {
|
.heading {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
Reference in New Issue
Block a user