diff options
Diffstat (limited to 'src/lib/Utility/proxy.ts')
| -rw-r--r-- | src/lib/Utility/proxy.ts | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/Utility/proxy.ts b/src/lib/Utility/proxy.ts index 32f31226..57883836 100644 --- a/src/lib/Utility/proxy.ts +++ b/src/lib/Utility/proxy.ts @@ -1,11 +1,24 @@ +import { env } from "$env/dynamic/public"; import { isLocalApp } from "$lib/Utility/appOrigin"; +const DEFAULT_PROXY_ORIGIN = "https://proxy.due.moe"; + +const normaliseOrigin = (origin: string) => + origin.endsWith("/") ? origin.slice(0, -1) : origin; + +export const proxyOrigin = () => + normaliseOrigin(env.PUBLIC_PROXY_ORIGIN || DEFAULT_PROXY_ORIGIN); + +export const proxyRoute = (path = "/") => + `${proxyOrigin()}${path.startsWith("/") ? path : `/${path}`}`; + export const proxy = (url: string, disable = false) => { const randomKey = Math.floor(Math.random() * 90) + 10; + const forcedProxy = Boolean(env.PUBLIC_PROXY_ORIGIN); - return isLocalApp() && !disable + return isLocalApp() && !disable && !forcedProxy ? url - : `https://proxy.due.moe/?d2=${btoa( + : `${proxyOrigin()}/?d2=${btoa( url .split("") .map((char) => char.charCodeAt(0) + randomKey) |