From 64c337dd05c4e1593de2d0d9faf8677a17d98864 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Mon, 18 Mar 2024 23:28:29 +1300 Subject: [PATCH] Fixed proxying --- materialious/src/lib/Api/index.ts | 4 +- materialious/src/lib/Logo.svelte | 7 +++- materialious/src/lib/Player.svelte | 39 ++++++++++++------- materialious/src/routes/watch/[slug]/+page.ts | 4 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index d66f1a3e..d05ec226 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -20,8 +20,8 @@ export async function getPopular(): Promise { return await resp.json(); } -export async function getVideo(videoId: string): Promise { - const resp = await fetch(buildPath(`videos/${videoId}`)); +export async function getVideo(videoId: string, local: boolean = false): Promise { + const resp = await fetch(buildPath(`videos/${videoId}?local=${local}`)); return await resp.json(); } diff --git a/materialious/src/lib/Logo.svelte b/materialious/src/lib/Logo.svelte index 9a131518..d0d0f482 100644 --- a/materialious/src/lib/Logo.svelte +++ b/materialious/src/lib/Logo.svelte @@ -1,4 +1,9 @@ - { + if (proxyVideos) { + const rawSrc = new URL(format.url); + rawSrc.host = import.meta.env.VITE_DEFAULT_INVIDIOUS_INSTANCE.replace( + 'http://', + '' + ).replace('https://', ''); + + src = rawSrc.toString(); + } else { + src = format.url; + } return { - src: format.url + (proxyVideos ? '?local=true' : ''), + src: src, size: Number(format.size.split('x')[1]), type: format.type }; diff --git a/materialious/src/routes/watch/[slug]/+page.ts b/materialious/src/routes/watch/[slug]/+page.ts index d9aaf5d9..b3f730dd 100644 --- a/materialious/src/routes/watch/[slug]/+page.ts +++ b/materialious/src/routes/watch/[slug]/+page.ts @@ -1,9 +1,9 @@ import { amSubscribed, getComments, getDislikes, getVideo, postHistory } from '$lib/Api/index.js'; import { get } from 'svelte/store'; -import { auth } from '../../../store'; +import { auth, playerProxyVideos } from '../../../store'; export async function load({ params }) { - const video = await getVideo(params.slug); + const video = await getVideo(params.slug, get(playerProxyVideos)); if (get(auth)) { postHistory(video.videoId); }