Implemented fix for url crashing
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user