Replace deprecated base by resolve

See https://svelte.dev/docs/kit/$app-paths
This commit is contained in:
Precific
2025-11-02 18:21:10 +01:00
parent 06bad1753c
commit 98dd617690
21 changed files with 69 additions and 66 deletions
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { getBestThumbnail, proxyGoogleImage } from '$lib/images';
import { cleanNumber } from '$lib/numbers';
import { onMount } from 'svelte';
@@ -29,7 +29,7 @@
});
</script>
<a href={`${base}/channel/${channel.authorId}`} class="wave" style="min-width: 100%;min-height: 100%;">
<a href={resolve(`/channel/${channel.authorId}`)} class="wave" style="min-width: 100%;min-height: 100%;">
<div class="padding">
{#if !$interfaceLowBandwidthMode}
<div class="center-align">
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { getComments } from '$lib/api';
import { type Comment, type Comments } from '$lib/api/model';
import { getBestThumbnail, proxyGoogleImage } from '$lib/images';
@@ -35,7 +35,7 @@
function commentTimestamps(html: string): string {
const regex =
/<a href="([^"]+)" data-onclick="jump_to_time" data-jump-time="(\d+)">([^<]+)<\/a>\s*(.+)/g;
const replacement = `<a href="${base}/watch/${videoId}?time=$2" data-sveltekit-preload-data="off" class="link">$3 $4</a>`;
const replacement = `<a href=${resolve(`/watch/${videoId}?time=$2`)} data-sveltekit-preload-data="off" class="link">$3 $4</a>`;
const processedHtml = html.replace(regex, replacement);
@@ -64,7 +64,7 @@
<progress class="circle"></progress>
{/if}
<div class="comment-info">
<a href={`${base}/channel/${comment.authorId}`} class="author">
<a href={resolve(`/channel/${comment.authorId}`)} class="author">
<span class="bold" class:channel-owner={comment.authorIsChannelOwner}>
{comment.author}
</span>
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { cleanNumber } from '$lib/numbers';
import { _ } from '$lib/i18n';
import type { HashTag } from '../api/model';
@@ -12,7 +12,7 @@
let { hashtag }: Props = $props();
</script>
<a href={base+hashtag.url} class="wave" style="min-width: 100%;min-height: 100%;">
<a href={resolve(hashtag.url)} class="wave" style="min-width: 100%;min-height: 100%;">
<div class="padding">
<h5 class="center-align">{truncate(hashtag.title, 14)}</h5>
<h6 style="margin-top: 0;" class="center-align grey-text medium-text">
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { page } from '$app/stores';
import { getBestThumbnail } from '$lib/images';
import { padTime, videoLength } from '$lib/numbers';
@@ -694,7 +694,7 @@
if (!data.playlistId) {
if ($playerAutoplayNextByDefaultStore) {
goto(
`${base}/${$isAndroidTvStore ? 'tv' : 'watch'}/${data.video.recommendedVideos[0].videoId}`,
resolve(`/${$isAndroidTvStore ? 'tv' : 'watch'}/${data.video.recommendedVideos[0].videoId}`),
{ replaceState: $isAndroidTvStore }
);
}
@@ -740,7 +740,7 @@
}
goto(
`${base}/${$isAndroidTvStore ? 'tv' : 'watch'}/${goToVideo.videoId}?playlist=${data.playlistId}`,
resolve(`/${$isAndroidTvStore ? 'tv' : 'watch'}/${goToVideo.videoId}?playlist=${data.playlistId}`),
{ replaceState: $isAndroidTvStore }
);
}
@@ -1,5 +1,6 @@
<script lang="ts">
import { base } from '$app/paths';
import { getBestThumbnail } from '$lib/images';
import { resolve } from '$app/paths';
import { letterCase } from '$lib/letterCasing';
import { onMount } from 'svelte';
import { _ } from '$lib/i18n';
@@ -48,7 +49,7 @@
</script>
<a
href={base+playlistLink}
href={resolve(playlistLink)}
class:link-disabled={disabled}
style="width: 100%; overflow: hidden;min-height:100px;"
class="wave"
@@ -77,11 +78,11 @@
<div class="small-padding">
<nav class="no-margin">
<div class="max">
<a class:link-disabled={disabled} href={base+playlistLink}
<a class:link-disabled={disabled} href={resolve(playlistLink)}
><div class="bold">{letterCase(truncate(playlist.title))}</div></a
>
<div>
<a class:link-disabled={playlist.authorId === null} href={`${base}/channel/${playlist.authorId}`}
<a class:link-disabled={playlist.authorId === null} href={resolve(`/channel/${playlist.authorId}`)}
>{playlist.author}</a
>
</div>
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { goto } from '$app/navigation';
import Mousetrap from 'mousetrap';
import { createEventDispatcher, onMount, tick } from 'svelte';
@@ -43,7 +43,7 @@
if (search.trim() === '') return;
selectedSuggestionIndex = -1;
goto(`${base}/search/${encodeURIComponent(search)}`);
goto(resolve(`/search/${encodeURIComponent(search)}`));
suggestionsForSearch = [];
showSearchBox = false;
@@ -155,7 +155,7 @@
handleSubmit();
}}
class:selected={index === selectedSuggestionIndex}
href={`${base}/search/${encodeURIComponent(suggestion)}`}
href={resolve(`/search/${encodeURIComponent(suggestion)}`)}
>
<div>{suggestion}</div>
</a>
@@ -169,7 +169,7 @@
onclick={() => {
search = history;
}}
href={`${base}/search/${encodeURIComponent(history)}`}
href={resolve(`/search/${encodeURIComponent(history)}`)}
>
<div>{history}</div>
</a>
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { bookmarkletSaveToUrl } from '$lib/externalSettings';
import { letterCase, titleCases } from '$lib/letterCasing';
import { setAmoledTheme } from '$lib/theme';
@@ -90,7 +90,7 @@
instanceStore.set(instance);
authStore.set(null);
goto(base+'/', { replaceState: true });
goto(resolve('/'), { replaceState: true });
ui('#dialog-settings');
}
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { instanceStore } from '$lib/store';
import { Clipboard } from '@capacitor/clipboard';
import { Capacitor } from '@capacitor/core';
@@ -34,7 +34,7 @@
if (Capacitor.isNativePlatform()) {
url = `${get(instanceStore)}/watch/${video.videoId}`;
} else {
url = `${location.origin}${base}/watch/${video.videoId}`;
url = `${location.origin}`+resolve(`/watch/${video.videoId}`);
}
if (includeTimestamp && currentTime !== undefined) {
url += `?time=${Math.floor(currentTime)}`;
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { page } from '$app/stores';
import { peerJs, removeWindowQueryFlag, setWindowQueryFlag } from '$lib/misc';
import type { PlayerEvents } from '$lib/player';
@@ -21,7 +21,7 @@
events.events.forEach((event) => {
if (event.type === 'change-video' && event.videoId) {
currentUrl.pathname = `${base}/watch/${event.videoId}`;
currentUrl.pathname = resolve(`/watch/${event.videoId}`);
goto(currentUrl);
} else if (event.type === 'goto' && event.path && event.path !== $page.url.pathname) {
if (blockedPages.includes(event.path.replace('/', ''))) {
@@ -73,7 +73,7 @@
}
page.subscribe((newPage) => {
if (!newPage.url.pathname.startsWith(base+'/watch') && $syncPartyPeerStore) {
if (!newPage.url.pathname.startsWith(resolve('/watch')) && $syncPartyPeerStore) {
$syncPartyConnectionsStore?.forEach((conn) => {
conn.send({
events: [
@@ -125,14 +125,16 @@
<input
name="sync-share"
readonly
value={`${location.origin}${base}/?sync=${$syncPartyPeerStore.id}`}
value={`${location.origin}`+resolve(`/?sync=${$syncPartyPeerStore.id}`)}
type="text"
/>
<label class="active" for="sync-share">Share URL</label>
</div>
<button
onclick={async () => {
await Clipboard.write({ string: `${location.origin}${base}/?sync=${$syncPartyPeerStore?.id}` });
await Clipboard.write({
string: `${location.origin}`+resolve(`/?sync=${$syncPartyPeerStore?.id}`)
});
}}
class="square round"
>
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { getBestThumbnail } from '$lib/images';
import { letterCase } from '$lib/letterCasing';
import { cleanNumber, videoLength } from '$lib/numbers';
@@ -215,7 +215,7 @@
</a>
<div>
<a tabindex="-1" class:author={!sideways} href={`${base}/channel/${video.authorId}`}
<a tabindex="-1" class:author={!sideways} href={resolve(`/channel/${video.authorId}`)}
>{video.author}
</a>
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { deleteUnsubscribe, postSubscribe } from '$lib/api';
import type { VideoPlay } from '$lib/api/model';
import { getBestThumbnail, proxyGoogleImage } from '$lib/images';
@@ -22,7 +22,7 @@
</script>
<nav>
<a href={`${base}/channel/${video.authorId}`}>
<a href={resolve(`/channel/${video.authorId}`)}>
<nav style="gap: 0.5em;">
{#if !$interfaceLowBandwidthMode}
<img
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { numberWithCommas } from '$lib/numbers';
import { _ } from '$lib/i18n';
import type { VideoPlay } from '$lib/api/model';
@@ -35,7 +35,7 @@
<article class="border">
<nav class="scroll">
{#each video.keywords as keyword}
<a href={`${base}/search/${encodeURIComponent(keyword)}`} class="chip">{keyword}</a>
<a href={resolve(`/search/${encodeURIComponent(keyword)}`)} class="chip">{keyword}</a>
{/each}
</nav>
</article>
+3 -4
View File
@@ -1,5 +1,5 @@
import { pushState } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { page } from '$app/stores';
import he from 'he';
import type Peer from 'peerjs';
@@ -139,9 +139,8 @@ export function expandSummery(id: string) {
}
export function createVideoUrl(videoId: string, playlistId: string): URL {
const watchUrl = new URL(
`${location.origin}${base}/${get(isAndroidTvStore) ? 'tv' : 'watch'}/${videoId}`
);
const watchPath = resolve(`/${get(isAndroidTvStore) ? 'tv' : 'watch'}/${videoId}`);
const watchUrl = new URL(`${location.origin}${watchPath}`);
if (playlistId !== '') {
watchUrl.searchParams.set('playlist', playlistId);
+8 -8
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { goto } from '$app/navigation';
import { navigating, page } from '$app/stores';
@@ -92,7 +92,7 @@
return;
}
goto(`${base}/watch/${videoId}`);
goto(resolve(`/watch/${videoId}`));
} else {
// Auth response handling for Mobile
const username = url.searchParams.get('username');
@@ -118,7 +118,7 @@
path.search = searchParams.toString();
await Browser.open({ url: path.toString() });
} else {
searchParams.set('callback_url', `${location.origin}${base}/auth`);
searchParams.set('callback_url', `${location.origin}`+resolve('/auth'));
path.search = searchParams.toString();
document.location.href = path.toString();
}
@@ -163,7 +163,7 @@
console.log(sid);
authStore.set({ username: rawUsername, token: sid });
await ui('#tv-login');
goto(base+'/', { replaceState: true });
goto(resolve('/'), { replaceState: true });
return;
}
}
@@ -177,7 +177,7 @@
feedCacheStore.set({});
searchCacheStore.set({});
playlistCacheStore.set({});
goto(base+'/');
goto(resolve('/'));
}
async function loadNotifications() {
@@ -267,7 +267,7 @@
<nav class="left m l surface-container" class:tv-nav={$isAndroidTvStore}>
<header
role="presentation"
onclick={() => goto(base+$interfaceDefaultPage)}
onclick={() => goto(resolve($interfaceDefaultPage))}
style="cursor: pointer;"
tabindex="-1"
class="small-padding"
@@ -276,7 +276,7 @@
</header>
{#each getPages() as navPage}
{#if !navPage.requiresAuth || isLoggedIn}
<a href={base+navPage.href} class:active={$page.url.href.endsWith(navPage.href)}
<a href={resolve(navPage.href)} class:active={$page.url.href.endsWith(navPage.href)}
><i>{navPage.icon}</i>
<div>{navPage.name}</div>
</a>
@@ -355,7 +355,7 @@
{#if !navPage.requiresAuth || isLoggedIn}
<a
class="round"
href={base+navPage.href}
href={resolve(navPage.href)}
class:active={$page.url.href.endsWith(navPage.href)}
data-sveltekit-preload-data="off"
><i>{navPage.icon}</i>
@@ -1,6 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { page } from '$app/stores';
import PageLoading from '$lib/components/PageLoading.svelte';
import { authStore } from '$lib/store';
@@ -18,7 +18,7 @@
});
}
goto(base+'/');
goto(resolve('/'));
});
</script>
@@ -1,11 +1,11 @@
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { error } from '@sveltejs/kit';
export async function load({ url }) {
const playlistId = url.searchParams.get('list');
if (playlistId) {
goto(`${base}/playlist/${playlistId}`);
goto(resolve(`/playlist/${playlistId}`));
} else {
error(404);
}
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { unsafeRandomItem } from '$lib/misc';
import { cleanNumber } from '$lib/numbers';
import { isAndroidTvStore, playlistSettingsStore } from '$lib/store';
@@ -16,8 +16,8 @@
<nav>
<a
href={!$isAndroidTvStore
? `${base}/watch/${data.playlist.videos[0].videoId}?playlist=${data.playlist.info.playlistId}`
: `${base}/tv/${data.playlist.videos[0].videoId}?playlist=${data.playlist.info.playlistId}`}
? resolve(`/watch/${data.playlist.videos[0].videoId}?playlist=${data.playlist.info.playlistId}`)
: resolve(`/tv/${data.playlist.videos[0].videoId}?playlist=${data.playlist.info.playlistId}`)}
class="button circle extra no-margin"
>
<i>play_arrow</i>
@@ -28,8 +28,8 @@
<a
href={!$isAndroidTvStore
? `${base}/watch/${unsafeRandomItem(data.playlist.videos).videoId}?playlist=${data.playlist.info.playlistId}`
: `${base}/tv/${unsafeRandomItem(data.playlist.videos).videoId}?playlist=${data.playlist.info.playlistId}`}
? resolve(`/watch/${unsafeRandomItem(data.playlist.videos).videoId}?playlist=${data.playlist.info.playlistId}`)
: resolve(`/tv/${unsafeRandomItem(data.playlist.videos).videoId}?playlist=${data.playlist.info.playlistId}`)}
onclick={() =>
playlistSettingsStore.set({
[data.playlist.info.playlistId]: { shuffle: true, loop: false }
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { deleteUnsubscribe } from '$lib/api';
import Fuse from 'fuse.js';
import { _ } from '$lib/i18n';
@@ -46,7 +46,7 @@
{#each subscriptions as sub}
<article>
<nav>
<a href={`${base}/channel/${sub.authorId}`}
<a href={resolve(`/channel/${sub.authorId}`)}
><h6>
{sub.author}
</h6></a
+2 -2
View File
@@ -1,5 +1,5 @@
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import { error } from '@sveltejs/kit';
export async function load({ url }) {
@@ -8,7 +8,7 @@ export async function load({ url }) {
const timestamp = url.searchParams.get('t');
if (videoId) {
let goToUrl = new URL(`${location.origin}${base}/watch/${videoId}`);
let goToUrl = new URL(`${location.origin}`+resolve(`/watch/${videoId}`));
if (playlistId) {
goToUrl.searchParams.set('playlist', playlistId);
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import {
addPlaylistVideo,
getComments,
@@ -502,7 +502,7 @@
{$_('videos')}
</p>
<p>
<a href={`${base}/channel/${$playlistCacheStore[data.playlistId].info.authorId}`}
<a href={resolve(`/channel/${$playlistCacheStore[data.playlistId].info.authorId}`)}
>{$playlistCacheStore[data.playlistId].info.author}</a
>
</p>
+7 -6
View File
@@ -1,6 +1,6 @@
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { resolve } from '$app/paths';
import androidTv from '$lib/android/plugins/androidTv';
import { getResolveUrl } from '$lib/api';
import '$lib/i18n'; // Import to initialize. Important :)
@@ -18,13 +18,14 @@ export async function load({ url }) {
isAndroidTvStore.set((await androidTv.isAndroidTv()).value);
if (url.pathname.startsWith(base+'/@')) {
const username = url.pathname.substring(base.length).split('/')[1];
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(`${base}/channel/${resolvedUrl.ucid}`);
goto(resolve(`/channel/${resolvedUrl.ucid}`));
}
} catch {}
}
@@ -35,12 +36,12 @@ export async function load({ url }) {
defaultPage &&
defaultPage !== '/' &&
defaultPage.startsWith('/') &&
url.pathname === base+'/' &&
url.pathname === resolvedRoot &&
window.history.length < 3
) {
getPages().forEach((page) => {
if (page.href === defaultPage && (!page.requiresAuth || get(authStore))) {
goto(base+defaultPage);
goto(resolve(defaultPage));
}
});
}