Merge pull request #12 from movie-web/dev

Update providers-api
This commit is contained in:
William Oldham
2024-01-06 18:37:40 +00:00
committed by GitHub

View File

@@ -9,9 +9,21 @@ export function getProviders(context: Context<Env>) {
const specialDomains = specialDomainsEnv.split(",").map(v=>v.trim()).filter(v=>v.length>0);
const fetcher: RealFetcher = (u,ops) => {
const url = new URL(u);
if (specialDomains.includes(url.hostname) && !!proxyUrl)
return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops);
let url: URL | null = null;
try {
if (ops.baseUrl) {
const baseUrl = ops.baseUrl.endsWith("/") ? ops.baseUrl.slice(0, -1) : ops.baseUrl;
const path = u.startsWith("/") ? u : u.slice(0, -1);
url = new URL(baseUrl + path);
} else {
url = new URL(u);
}
if (specialDomains.includes(url.hostname) && !!proxyUrl)
return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops);
} catch {
return standardFetcher(u, ops);
}
return standardFetcher(u, ops);
};