refactor: move sibnet parsing to another place

This commit is contained in:
Kentai Radiquum 2025-03-16 13:07:30 +05:00
parent 279db4b4cb
commit 17e0c0e770
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
2 changed files with 8 additions and 216 deletions

View file

@ -16,118 +16,9 @@ export default async function middleware(
if (isApiV2) {
url.searchParams.delete("API-Version");
}
const isHTML = url.searchParams.get("html") == "true" || false;
if (isHTML) {
url.searchParams.delete("html");
}
const isNotAnixart =
url.searchParams.get("isNotAnixart") == "true" || false;
if (isNotAnixart) {
url.searchParams.delete("isNotAnixart");
}
const isSibnet = url.searchParams.get("isSibnet") == "true" || false;
if (isSibnet) {
url.searchParams.delete("isSibnet");
}
let path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
let data = null;
path = decodeURIComponent(path);
console.log(path);
// if (
// (isHTML || isNotAnixart || isSibnet) &&
// !(
// path.startsWith("https://kodik.info") ||
// path.startsWith("https://aniqit.com") ||
// path.startsWith("https://video.sibnet.ru") ||
// path.includes("sibnet.ru")
// )
// ) {
// console.log("URL NOT ALLOWED");
// return new Response(JSON.stringify({ message: "URL not allowed" }), {
// status: 403,
// headers: {
// "Content-Type": "application/json",
// },
// });
// }
if (isSibnet) {
const page = await fetch(`https://${path}`, {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
},
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
const pageData = await page.text();
const videoRe = /\/v\/.*?\.mp4/;
const video = videoRe.exec(pageData);
if (!video || video.length == 0) {
return new Response(JSON.stringify({ message: "Sibnet: Video not found" }), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
const posterRe = /\/upload\/cover\/.*?\.jpg/;
const posterUrl = posterRe.exec(pageData);
if (!posterUrl || posterUrl.length == 0) {
return new Response(JSON.stringify({ message: "Sibnet: Poster not found" }), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
const response = await fetch(`https://video.sibnet.ru${video[0]}`, {
redirect: "manual",
headers: {
referer: `https://${path}`,
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
},
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
return new Response(JSON.stringify({ url: `https:${response.headers.get("Location")}`, poster: `https://st.sibnet.ru${posterUrl[0]}` }), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}
if (isHTML) {
const response = await fetch(`https://${path}`);
data = await response.text();
return new Response(data, {
status: 200,
headers: {
"Content-Type": "text/html",
},
});
} else if (isNotAnixart) {
data = await fetchDataViaGet(`https://${path}`);
} else {
data = await fetchDataViaGet(`${API_URL}/${path}`, isApiV2);
}
const data = await fetchDataViaGet(`${API_URL}/${path}`, isApiV2);
if (!data) {
return new Response(JSON.stringify({ message: "Error Fetching Data" }), {
@ -152,60 +43,7 @@ export default async function middleware(
if (isApiV2) {
url.searchParams.delete("API-Version");
}
const isNotAnixart =
url.searchParams.get("isNotAnixart") == "true" || false;
if (isNotAnixart) {
url.searchParams.delete("isNotAnixart");
}
let path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
path = decodeURIComponent(path);
console.log(path);
if (isNotAnixart) {
// if (
// !(
// path.startsWith("https://kodik.info") ||
// path.startsWith("https://aniqit.com")
// )
// ) {
// console.log("URL NOT ALLOWED");
// return new Response(JSON.stringify({ message: "URL not allowed" }), {
// status: 403,
// headers: {
// "Content-Type": "application/json",
// },
// });
// }
const params = await request.json()
const formData = new FormData();
for (const [key, value] of Object.entries(params)) {
formData.append(key as any, value as any);
}
const response = await fetch(`https://anix-c.wah.su/https://${path}`, {
method: "POST",
body: formData,
headers: {
origin: "anix.wah.su"
}
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
const data = await response.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}
const path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
const ReqContentTypeHeader = request.headers.get("Content-Type") || "";
let ResContentTypeHeader = "";