Re-implement domain normalization
This commit is contained in:
parent
a5314e5923
commit
23fdf5ab07
2 changed files with 10 additions and 5 deletions
|
@ -65,7 +65,7 @@ const { prefilledInstance } = Astro.props;
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { extractHost, normalizeURL } from "@scripts/util";
|
import { getUrlDomain, normalizeURL } from "@scripts/util";
|
||||||
import {
|
import {
|
||||||
savedInstances as instanceStore,
|
savedInstances as instanceStore,
|
||||||
saveInstance,
|
saveInstance,
|
||||||
|
@ -88,7 +88,7 @@ const { prefilledInstance } = Astro.props;
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = extractHost(instance);
|
const host = getUrlDomain(instance);
|
||||||
if (index == 0 && !$instance.value) {
|
if (index == 0 && !$instance.value) {
|
||||||
$instance.value = host;
|
$instance.value = host;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,14 @@ export const normalizeURL = (url: string): string => {
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractHost = (url: string): string => {
|
export const getUrlDomain = (url: string | URL): string => {
|
||||||
if (!(url.startsWith("https://") || url.startsWith("http://"))) {
|
if (typeof url === "string") {
|
||||||
url = "https://" + url;
|
url = url.trim();
|
||||||
|
|
||||||
|
if (!/^https?:\/\//.test(url)) {
|
||||||
|
url = `https://${url}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new URL(url).host;
|
return new URL(url).host;
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue