ملخص المباراة رقم 6
export default {
async fetch(request, env, ctx) {
const referer = request.headers.get("Referer") || "";
const origin = request.headers.get("Origin") || "";
const allowedDomain = "123tv.fun";
if (
!referer.includes(allowedDomain) &&
!origin.includes(allowedDomain)
) {
return new Response("Forbidden", { status: 403 });
}
const target = new URL(request.url).searchParams.get("url");
if (!target) {
return new Response("Missing url", { status: 400 });
}
const isM3U8 = target.includes(".m3u8");
const isTS = target.includes(".ts");
const cache = caches.default;
const cacheKey = new Request(request.url, request);
if (!isM3U8) {
const cached = await cache.match(cacheKey);
if (cached) {
return cached;
}
}
const res = await fetch(target, {
headers: {
"Referer": "https://player.syria-player.live/albaplayer/beinmax3/?serv=1",
"origin": "https://player.syria-player.live",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
}
});
let response;
if (isM3U8) {
let text = await res.text();
const base = target.substring(
0,
target.lastIndexOf("/") + 1
);
text = text.replace(
/^(?!#)(.+)$/gm,
line => {
if (!line.trim()) return line;
if (
line.startsWith("http://") ||
line.startsWith("https://")
) {
return request.url.split("?")[0] +
"?url=" +
encodeURIComponent(line);
}
return request.url.split("?")[0] +
"?url=" +
encodeURIComponent(base + line);
}
);
response = new Response(text, {
headers: {
"Content-Type": "application/vnd.apple.mpegurl",
"Access-Control-Allow-Origin": "*",
"Cache-Control": "no-store, no-cache, must-revalidate"
}
});
} else {
const headers = new Headers(res.headers);
if (isTS) {
headers.set("Content-Type", "video/mp2t");
headers.set("Cache-Control", "public, max-age=180");
}
headers.set("Access-Control-Allow-Origin", "*");
response = new Response(res.body, {
status: res.status,
statusText: res.statusText,
headers
});
ctx.waitUntil(
cache.put(cacheKey, response.clone())
);
}
return response;
}
};