Implemented fix for url crashing

This commit is contained in:
2021-04-07 19:44:44 +02:00
parent ca48959581
commit 7f6134d0ef
3 changed files with 32 additions and 24 deletions

View File

@@ -1,5 +1,7 @@
<script>
import { apikey, lang, stationinfo, api_endpoint } from "./store.js";
import isURL from "validator/lib/isURL";
import isUUID from "validator/lib/isUUID";
import axios from "axios";
import { _, locale } from "svelte-i18n";
let token;
@@ -10,30 +12,7 @@
token?.length === 44 &&
token.split(".")[0].length === 7 &&
isUUID(token.split(".")[1]);
$: isEndpointValid = validURL(api_endpoint_input);
function validURL(str) {
var pattern = new RegExp(
"^(https?:\\/\\/)?" + // protocol
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
"((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
"(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
"(\\#[-a-z\\d_]*)?$",
"i"
); // fragment locator
return !!pattern.test(str);
}
function isUUID(uuid) {
let s = "" + uuid;
s = s.match(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
);
if (s === null) {
return false;
}
return true;
}
$: isEndpointValid = isURL(api_endpoint_input);
</script>
<div class="w-full flex flex-wrap">