Added instance URL validation
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
let forceCase = $state(get(interfaceForceCase));
|
||||
let defaultPage = $state(get(interfaceDefaultPage));
|
||||
|
||||
let invalidInstance = $state(false);
|
||||
|
||||
async function setColor(color: any) {
|
||||
const target = color.target;
|
||||
const hex = (target as { value: string }).value;
|
||||
@@ -55,21 +57,44 @@
|
||||
darkModeStore.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
async function setInstance(event: Event) {
|
||||
event.preventDefault();
|
||||
|
||||
invalidInstance = false;
|
||||
|
||||
const instance = ensureNoTrailingSlash(invidiousInstance);
|
||||
|
||||
try {
|
||||
new URL(instance);
|
||||
} catch {
|
||||
invalidInstance = true;
|
||||
}
|
||||
|
||||
if (invalidInstance) return;
|
||||
|
||||
const resp = await fetch(`${instance}/api/v1/trending`);
|
||||
if (!resp.ok) {
|
||||
invalidInstance = true;
|
||||
return;
|
||||
}
|
||||
|
||||
instanceStore.set(instance);
|
||||
authStore.set(null);
|
||||
goto('/', { replaceState: true });
|
||||
ui('#dialog-settings');
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if Capacitor.isNativePlatform()}
|
||||
<form
|
||||
onsubmit={preventDefault(() => {
|
||||
instanceStore.set(ensureNoTrailingSlash(invidiousInstance));
|
||||
authStore.set(null);
|
||||
goto('/', { replaceState: true });
|
||||
ui('#dialog-settings');
|
||||
})}
|
||||
>
|
||||
<form style="margin-bottom: 2em;" onsubmit={setInstance}>
|
||||
<nav>
|
||||
<div class="field label border max">
|
||||
<div class="field label border max" class:invalid={invalidInstance}>
|
||||
<input bind:value={invidiousInstance} name="invidious-instance" type="text" />
|
||||
<label for="invidious-instance">{$_('layout.instanceUrl')}</label>
|
||||
{#if invalidInstance}
|
||||
<span class="error">{$_('invalidInstance')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<button class="square round">
|
||||
<i>done</i>
|
||||
@@ -78,8 +103,6 @@
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
<div class="margin"></div>
|
||||
|
||||
<button onclick={toggleDarkMode} class="no-margin">
|
||||
{#if !$darkModeStore}
|
||||
<i>dark_mode</i>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"copyUrl": "Copy URL",
|
||||
"loadMore": "Load more",
|
||||
"views": "views",
|
||||
"invalidInstance": "Please verify the URL. If it's correct, the instance may be down or may not support third-party clients.",
|
||||
"invidiousBlockWarning": "Invidious is currently being blocked by Google. If videos aren't loading for this instance, please use this instance on Materialious on {android} or {desktop} to get around this with local video fallback.",
|
||||
"videos": "videos",
|
||||
"cancel": "Cancel",
|
||||
@@ -161,4 +162,4 @@
|
||||
}
|
||||
},
|
||||
"subscribe": "Subscribe"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user