diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/Tools/Wrapped.svelte | 4 | ||||
| -rw-r--r-- | src/routes/api/proxy/+server.ts | 20 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte index 1914e29b..3361ba5e 100644 --- a/src/lib/Tools/Wrapped.svelte +++ b/src/lib/Tools/Wrapped.svelte @@ -285,8 +285,8 @@ // return string.slice(0, maxLength - 3) + ' …'; // }; - const proxy = (url: string) => - env.PUBLIC_ANILIST_REDIRECT_URI.includes('192.168') + const proxy = (url: string, disable = false) => + env.PUBLIC_ANILIST_REDIRECT_URI.includes('192.168') && !disable ? url : `/api/proxy?url=${encodeURIComponent(url)}`; </script> diff --git a/src/routes/api/proxy/+server.ts b/src/routes/api/proxy/+server.ts index 1c4a25dc..c4bf74a6 100644 --- a/src/routes/api/proxy/+server.ts +++ b/src/routes/api/proxy/+server.ts @@ -1,2 +1,18 @@ -export const GET = async ({ url }) => - new Response(await (await fetch(url.searchParams.get('url') as string)).blob()); +export const GET = async ({ url }) => { + const response = await fetch(url.searchParams.get('url') as string); + const contentType = response.headers.get('content-type') as string; + + if (contentType.includes('application/json')) { + return Response.json(await response.json(), { + headers: { 'Content-Type': 'application/json' } + }); + } else if (contentType.includes('text/html') || contentType.includes('text/plain')) { + return new Response(await response.text(), { + headers: { 'Content-Type': contentType } + }); + } else { + return new Response(await response.blob(), { + headers: { 'Content-Type': contentType } + }); + } +}; |