updated Nav-Search + removed string-sanitizer + added csgo-sharecode
Some checks failed
CSGOWTF/csgowtf/pipeline/head There was a failure building this commit

This commit is contained in:
2022-03-27 21:11:18 +02:00
parent 9ac3228f5d
commit afed42de49
7 changed files with 168 additions and 57 deletions

View File

@@ -32,7 +32,7 @@
</li>
</ul>
<form
id="searchform"
id="search-form"
class="d-flex"
@keydown.enter.prevent="parseSearch"
@submit.prevent="parseSearch"
@@ -47,8 +47,8 @@
aria-label="Search"
autocomplete="off"
class="form-control bg-transparent border-0"
placeholder="SteamID64, Profile Link or Custom URL"
title="SteamID64, Profile Link or Custom URL"
placeholder="SteamID, Profile Link or ShareCode"
title="SteamID, Profile Link or ShareCode"
type="search"
/>
<button
@@ -67,11 +67,24 @@
<script setup lang="ts">
import { reactive } from "vue";
import { closeNav, closeNavEventListener, GetUser, GoToPlayer } from "@/utils";
import {
CUSTOM_URL_PATTERN,
closeNav,
closeNavEventListener,
GetMatchDetails,
GetUser,
GoToMatch,
GoToPlayer,
ParseMatch,
parseShareCode,
sleep,
stringSanitizer,
} from "@/utils";
import {
CUSTOM_URL_BASE,
ID64_PATTERN,
PROFILE_URL_PATTERN,
MATCH_SHARE_URL_BASE,
PROFILE_URL_BASE,
SHARECODE_REGEX,
VANITY_PATTERN,
} from "@/constants";
import { StatusCodes as STATUS } from "http-status-codes";
@@ -89,46 +102,57 @@ const data = reactive({
});
const parseSearch = async () => {
const input = data.searchInput;
let input = data.searchInput;
searchParamsStore.vanity_url = "";
searchParamsStore.id64 = "";
searchParamsStore.$reset();
if (data.searchInput !== "") {
if (ID64_PATTERN.test(input)) {
searchParamsStore.id64 = input;
} else if (input.match(CUSTOM_URL_PATTERN)) {
searchParamsStore.vanity_url = input.split("/")[4].split("?")[0];
} else if (input.match(PROFILE_URL_PATTERN)) {
const tmp = input.split("/")[4].split("?")[0];
if (ID64_PATTERN.test(tmp)) {
searchParamsStore.id64 = tmp;
// remove various base-urls + cut excess parameters
input = input
.replace(MATCH_SHARE_URL_BASE, "")
.replace(CUSTOM_URL_BASE, "")
.replace(PROFILE_URL_BASE, "")
.split("/")[0]
.split("?")[0];
// process shareCode
const tmpShareCode = Array.from(input.matchAll(SHARECODE_REGEX));
const inputShareCode = tmpShareCode.length > 0 ? tmpShareCode[0][0] : "";
searchParamsStore.shareCode = SHARECODE_REGEX.test(inputShareCode)
? inputShareCode
: "";
// process id64
const tmpId64 = Array.from(input.matchAll(ID64_PATTERN));
const inputId64 = tmpId64.length > 0 ? tmpId64[0][0] : "";
searchParamsStore.id64 = ID64_PATTERN.test(inputId64) ? inputId64 : "";
// process vanityUrl
if (searchParamsStore.shareCode === "" && searchParamsStore.id64 === "") {
if (input.includes(CUSTOM_URL_BASE)) {
input = input.replace(CUSTOM_URL_BASE, "");
}
if (VANITY_PATTERN.test(input)) {
searchParamsStore.vanityUrl = stringSanitizer(input);
} else {
const info: infoState = {
statusCode: STATUS.NOT_ACCEPTABLE,
message:
'Only alphanumeric symbols, "_", and "-", between 3-32 characters',
type: "warning",
};
infoStateStore.addInfo(info);
}
} else {
searchParamsStore.vanity_url = input;
}
if (
searchParamsStore.vanity_url !== "" &&
!VANITY_PATTERN.test(searchParamsStore.vanity_url)
) {
const info: infoState = {
statusCode: STATUS.NOT_ACCEPTABLE,
message:
'Only alphanumeric symbols, "_", and "-", between 3-32 characters',
type: "warning",
};
infoStateStore.addInfo(info);
searchParamsStore.vanity_url = "";
data.searchInput = "";
}
if (searchParamsStore.id64 !== "" || searchParamsStore.vanity_url !== "") {
const resData = await GetUser(
playerDetailsStore,
searchParamsStore.vanity_url || searchParamsStore.id64
// GetUser
if (searchParamsStore.id64 !== "" || searchParamsStore.vanityUrl !== "") {
const [resData, info] = await GetUser(
searchParamsStore.vanityUrl || searchParamsStore.id64
);
if (info.message !== "") infoStateStore.addInfo(info);
if (resData !== null) {
data.searchInput = "";
const activeElem = document.activeElement as HTMLInputElement;
@@ -136,15 +160,38 @@ const parseSearch = async () => {
playerDetailsStore.playerDetails = resData;
if (searchParamsStore.vanity_url) {
if (searchParamsStore.vanityUrl) {
closeNav("mainNav");
GoToPlayer(searchParamsStore.vanity_url);
GoToPlayer(searchParamsStore.vanityUrl);
} else if (searchParamsStore.id64) {
closeNav("mainNav");
GoToPlayer(searchParamsStore.id64);
}
}
}
// ParseMatch
if (searchParamsStore.shareCode !== "") {
data.searchInput = "";
const matchId = parseShareCode(searchParamsStore.shareCode);
let info = await ParseMatch(searchParamsStore.shareCode);
if (info.message !== "") infoStateStore.addInfo(info);
if (info.statusCode === STATUS.OK) GoToMatch(matchId);
if (info.statusCode === STATUS.ACCEPTED) {
let [res, info] = await GetMatchDetails(matchId);
for (let i = 0; i < 10; i++) {
if (res !== null && res.parsed) break;
[res, info] = await GetMatchDetails(matchId);
sleep(2000);
}
GoToMatch(matchId);
}
}
}
};