clean out in Nav component and improved vanity url filter

This commit is contained in:
cnachtigall1991
2021-10-15 04:57:23 +02:00
parent 74c484a791
commit a29f4b1f2a

View File

@@ -46,7 +46,6 @@
<script> <script>
import {reactive} from "vue"; import {reactive} from "vue";
import {useStore} from 'vuex' import {useStore} from 'vuex'
import {sanitize} from 'string-sanitizer'
import {GetUser, GoToLink, GoToPlayer} from '../utils' import {GetUser, GoToLink, GoToPlayer} from '../utils'
export default { export default {
@@ -63,6 +62,7 @@ export default {
const customUrlPattern = 'https://steamcommunity.com/id/' const customUrlPattern = 'https://steamcommunity.com/id/'
const profileUrlPattern = 'https://steamcommunity.com/profiles/' const profileUrlPattern = 'https://steamcommunity.com/profiles/'
const id64Pattern = /^\d{17}$/ const id64Pattern = /^\d{17}$/
const vanityPattern = /^[A-Za-z0-9-_]{3,32}$/
store.state.id64 = '' store.state.id64 = ''
store.state.vanityUrl = '' store.state.vanityUrl = ''
@@ -71,14 +71,21 @@ export default {
if (id64Pattern.test(input)) { if (id64Pattern.test(input)) {
store.state.id64 = input store.state.id64 = input
} else if (input.match(customUrlPattern)) { } 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)) { } else if (input.match(profileUrlPattern)) {
const tmp = input.split('/')[4].split('?')[0] const tmp = input.split('/')[4].split('?')[0]
if (id64Pattern.test(tmp)) { if (id64Pattern.test(tmp)) {
store.state.id64 = tmp store.state.id64 = tmp
} }
} else { } 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 !== '') { if (store.state.id64 !== '' || store.state.vanityUrl !== '') {
@@ -88,22 +95,24 @@ export default {
data.searchInput = '' data.searchInput = ''
document.activeElement.blur() document.activeElement.blur()
if (resData.vanity_url) { if (store.state.vanityUrl)
GoToPlayer(resData.vanity_url) GoToPlayer(store.state.vanityUrl)
} else if (resData.steamid64) { else if (store.state.id64)
GoToPlayer(resData.steamid64) GoToPlayer(store.state.id64)
}
} else if (res === 404) { } else if (res === 404) {
data.searchInput = '' data.searchInput = ''
data.error = `${resData} - Try again` data.error = `${resData} - Try again`
} else {
console.log(res, resData)
}
}
setTimeout(() => { setTimeout(() => {
data.error = '' data.error = ''
}, 5000) }, 5000)
} }
} }
}
}
return { return {
data, parseSearch, GoToLink data, parseSearch, GoToLink