clean out in Nav component and improved vanity url filter
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
<script>
|
||||
import {reactive} from "vue";
|
||||
import {useStore} from 'vuex'
|
||||
import {sanitize} from 'string-sanitizer'
|
||||
import {GetUser, GoToLink, GoToPlayer} from '../utils'
|
||||
|
||||
export default {
|
||||
@@ -63,6 +62,7 @@ export default {
|
||||
const customUrlPattern = 'https://steamcommunity.com/id/'
|
||||
const profileUrlPattern = 'https://steamcommunity.com/profiles/'
|
||||
const id64Pattern = /^\d{17}$/
|
||||
const vanityPattern = /^[A-Za-z0-9-_]{3,32}$/
|
||||
|
||||
store.state.id64 = ''
|
||||
store.state.vanityUrl = ''
|
||||
@@ -71,14 +71,21 @@ export default {
|
||||
if (id64Pattern.test(input)) {
|
||||
store.state.id64 = input
|
||||
} else if (input.match(customUrlPattern)) {
|
||||
store.state.vanityUrl = sanitize(input.split('/')[4].split('?')[0])
|
||||
store.state.vanityUrl = input.split('/')[4].split('?')[0]
|
||||
} else if (input.match(profileUrlPattern)) {
|
||||
const tmp = input.split('/')[4].split('?')[0]
|
||||
if (id64Pattern.test(tmp)) {
|
||||
store.state.id64 = tmp
|
||||
}
|
||||
} else {
|
||||
store.state.vanityUrl = sanitize(input)
|
||||
store.state.vanityUrl = input
|
||||
}
|
||||
|
||||
if (vanityPattern.test(store.state.vanityUrl)) {
|
||||
store.state.vanityUrl = input
|
||||
} else {
|
||||
data.error = 'Only alphanumeric symbols, "_", and "-", between 3-32 characters'
|
||||
store.state.vanityUrl = ''
|
||||
}
|
||||
|
||||
if (store.state.id64 !== '' || store.state.vanityUrl !== '') {
|
||||
@@ -88,20 +95,22 @@ export default {
|
||||
data.searchInput = ''
|
||||
document.activeElement.blur()
|
||||
|
||||
if (resData.vanity_url) {
|
||||
GoToPlayer(resData.vanity_url)
|
||||
} else if (resData.steamid64) {
|
||||
GoToPlayer(resData.steamid64)
|
||||
}
|
||||
if (store.state.vanityUrl)
|
||||
GoToPlayer(store.state.vanityUrl)
|
||||
else if (store.state.id64)
|
||||
GoToPlayer(store.state.id64)
|
||||
|
||||
} else if (res === 404) {
|
||||
data.searchInput = ''
|
||||
data.error = `${resData} - Try again`
|
||||
|
||||
setTimeout(() => {
|
||||
data.error = ''
|
||||
}, 5000)
|
||||
} else {
|
||||
console.log(res, resData)
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
data.error = ''
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user