Use throw redirect
This commit is contained in:
@@ -2,7 +2,7 @@ import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { getPopular } from '$lib/api/index';
|
||||
import { isYTBackend } from '$lib/misc';
|
||||
import { feedCacheStore } from '$lib/store';
|
||||
import { feedCacheStore, invidiousInstanceStore } from '$lib/store';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
@@ -12,6 +12,12 @@ export async function load() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!get(invidiousInstanceStore)) {
|
||||
return {
|
||||
popularDisabled: false
|
||||
};
|
||||
}
|
||||
|
||||
let popular = get(feedCacheStore).popular;
|
||||
let popularDisabled: boolean = false;
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { error, redirect } from '@sveltejs/kit';
|
||||
|
||||
export async function load({ url }) {
|
||||
const playlistId = url.searchParams.get('list');
|
||||
if (playlistId) {
|
||||
goto(resolve(`/playlist/[playlistId]`, { playlistId }));
|
||||
throw redirect(302, resolve(`/playlist/[playlistId]`, { playlistId }));
|
||||
} else {
|
||||
error(404);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export async function load({ params }) {
|
||||
goto(resolve('/watch/[videoId]', { videoId: params.slug }));
|
||||
throw redirect(302, resolve('/watch/[videoId]', { videoId: params.slug }));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export async function load({ url }) {
|
||||
const videoId = url.searchParams.get('v');
|
||||
const playlistId = url.searchParams.get('list');
|
||||
@@ -18,8 +19,7 @@ export async function load({ url }) {
|
||||
goToUrl.searchParams.set('time', timestamp);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
||||
goto(goToUrl);
|
||||
throw redirect(302, goToUrl);
|
||||
} else {
|
||||
error(404);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import androidTv from '$lib/android/plugins/androidTv';
|
||||
import { getResolveUrl } from '$lib/api';
|
||||
import '$lib/i18n'; // Import to initialize. Important :)
|
||||
import '$lib/i18n';
|
||||
import { initI18n } from '$lib/i18n';
|
||||
import { getPages } from '$lib/navPages';
|
||||
import {
|
||||
@@ -32,8 +32,6 @@ export async function load({ url }) {
|
||||
isAndroidTvStore.set((await androidTv.isAndroidTv()).value);
|
||||
|
||||
if (Capacitor.getPlatform() === 'android') {
|
||||
// Due to race condition with how we set & save persistent store values
|
||||
// we manually set stores like auth & instance before load.
|
||||
const preferenceKey: Record<string, Writable<any>> = {
|
||||
invidiousInstance: invidiousInstanceStore,
|
||||
authToken: invidiousAuthStore,
|
||||
@@ -42,22 +40,30 @@ export async function load({ url }) {
|
||||
};
|
||||
|
||||
for (const [key, store] of Object.entries(preferenceKey)) {
|
||||
const result = await Preferences.get({ key: key });
|
||||
if (result.value !== null) store.set(deserialize(result.value));
|
||||
const result = await Preferences.get({ key });
|
||||
if (result.value !== null) {
|
||||
store.set(deserialize(result.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedRoot = resolve('/', {});
|
||||
|
||||
if (url.pathname.startsWith(resolvedRoot + '@')) {
|
||||
const username = url.pathname.substring(resolvedRoot.length).split('/')[0];
|
||||
|
||||
try {
|
||||
const resolvedUrl = await getResolveUrl(`www.youtube.com/${username}`);
|
||||
if (resolvedUrl.pageType === 'WEB_PAGE_TYPE_CHANNEL') {
|
||||
goto(resolve(`/channel/[authorId]`, { authorId: resolvedUrl.ucid }));
|
||||
throw redirect(
|
||||
302,
|
||||
resolve(`/channel/[authorId]`, {
|
||||
authorId: resolvedUrl.ucid
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// continue regardless of error
|
||||
// ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,11 +76,11 @@ export async function load({ url }) {
|
||||
url.pathname === resolvedRoot &&
|
||||
window.history.length < 3
|
||||
) {
|
||||
getPages().forEach((page) => {
|
||||
for (const page of getPages()) {
|
||||
if (page.href === defaultPage && (!page.requiresAuth || get(invidiousAuthStore))) {
|
||||
goto(resolve(defaultPage, {}));
|
||||
throw redirect(302, resolve(defaultPage, {}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const isLoginPage = url.pathname.endsWith('/internal/login');
|
||||
@@ -82,9 +88,13 @@ export async function load({ url }) {
|
||||
|
||||
if (!isLoginPage) {
|
||||
if (isOwnBackend()?.requireAuth && !get(rawMasterKeyStore)) {
|
||||
goto(resolve('/internal/login', {}), { replaceState: true });
|
||||
} else if (!get(invidiousInstanceStore) && !isYTBackend() && !isSetupPage) {
|
||||
goto(resolve('/setup', {}), { replaceState: true });
|
||||
throw redirect(302, resolve('/internal/login', {}));
|
||||
}
|
||||
|
||||
if (!get(invidiousInstanceStore) && !isYTBackend() && !isSetupPage) {
|
||||
throw redirect(302, resolve('/setup', {}));
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user