Skip to content

Commit

Permalink
supports animepahe links
Browse files Browse the repository at this point in the history
  • Loading branch information
Toasty360 committed Dec 21, 2024
1 parent ee013e5 commit e1948fe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function proxy(request) {

const contentType = response.headers.get('content-type') || 'application/octet-stream';
const isM3U8 = videoContentTypes.some((type) => contentType.includes(type));
const responseContent = isM3U8 ? await response.text() : null;
let responseContent = isM3U8 ? await response.text() : null;
const cacheControl = isM3U8 ? getCacheSettings(mediaUrl, responseContent) : CACHE_CONTROL_SETTINGS.SEGMENT;

if (!isM3U8) {
Expand All @@ -146,7 +146,16 @@ async function proxy(request) {
await cache.put(cacheKey, newResponse.clone());
return newResponse;
}

responseContent = responseContent.replace(/URI=['"](.*?)['"]/, (_, url) => {
const fullUrl = url.startsWith('http')
? url
: url.startsWith('/')
? `${baseUrl.protocol}//${baseUrl.host}${url}`
: `${basePath}${url}`;
return `URI="${new URL(request.url).origin}/proxy?url=${encodeURIComponent(btoa(fullUrl))}&headers=${encodeURIComponent(
headersBase64
)}"`;
});
const modifiedBody = responseContent.replace(/^(?!#)([^\s]+)$/gm, (match) => {
const fullUrl = match.startsWith('http')
? match
Expand Down

0 comments on commit e1948fe

Please # to comment.