diff options
| author | Fuwn <[email protected]> | 2023-12-06 21:42:05 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-06 21:42:05 -0800 |
| commit | aef257cc7fe12c91c290efca0724a0264ffbc67d (patch) | |
| tree | 7b39e5745191783124d84ca268c5da5407e055c8 /src | |
| parent | feat(manga): add fetch delay (diff) | |
| download | due.moe-aef257cc7fe12c91c290efca0724a0264ffbc67d.tar.xz due.moe-aef257cc7fe12c91c290efca0724a0264ffbc67d.zip | |
feat(proxy): proxy all content
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 } + }); + } +}; |