mirror of
https://git.luna-app.eu/50n50/sources
synced 2026-01-12 01:18:11 +01:00
Update dev/dev.js
This commit is contained in:
parent
71f7d30321
commit
35bb4daaf2
1 changed files with 172 additions and 19 deletions
191
dev/dev.js
191
dev/dev.js
|
|
@ -1,25 +1,23 @@
|
|||
async function searchResults(keyword) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetchv2();
|
||||
const html = await response.text();
|
||||
const encodedKeyword = encodeURIComponent(keyword);
|
||||
const ddosInterceptor = new DdosGuardInterceptor();
|
||||
const responseText = await ddosInterceptor.fetchWithBypass(`https://animepahe.si/api?m=search&q=${encodedKeyword}`);
|
||||
const dataText = await responseText.text();
|
||||
console.log(dataText);
|
||||
const data = JSON.parse(dataText);
|
||||
const transformedResults = data.data.map(result => {
|
||||
return {
|
||||
title: result.title,
|
||||
image: result.poster,
|
||||
href: `https://animepahe.si/anime/${result.session}`
|
||||
};
|
||||
});
|
||||
|
||||
let match;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
results.push({
|
||||
title: match[3].trim(),
|
||||
image: match[2].trim(),
|
||||
href: match[1].trim()
|
||||
});
|
||||
}
|
||||
|
||||
return JSON.stringify(results);
|
||||
} catch (err) {
|
||||
return JSON.stringify([{
|
||||
title: "Error",
|
||||
image: "Error",
|
||||
href: "Error"
|
||||
}]);
|
||||
return JSON.stringify(transformedResults);
|
||||
} catch (error) {
|
||||
console.log("Fetch error in searchResults: " + error);
|
||||
return JSON.stringify([{ title: "Error", image: "", href: "" }]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,3 +73,158 @@ async function extractStreamUrl(url) {
|
|||
return "https://error.org/";
|
||||
}
|
||||
}
|
||||
|
||||
// Fixed DDOS Bypass
|
||||
class DdosGuardInterceptor {
|
||||
constructor() {
|
||||
this.errorCodes = [403];
|
||||
this.serverCheck = ["ddos-guard"];
|
||||
this.cookieStore = {};
|
||||
}
|
||||
|
||||
async fetchWithBypass(url, options = {}) {
|
||||
let response = await this.fetchWithCookies(url, options);
|
||||
|
||||
const isBlocked = await this.isBlockedResponse(response);
|
||||
|
||||
if (!isBlocked) {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
if (this.cookieStore["__ddg2_"]) {
|
||||
return this.fetchWithCookies(url, options);
|
||||
}
|
||||
|
||||
const newCookie = await this.getNewCookie(url);
|
||||
if (!newCookie) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return this.fetchWithCookies(url, options);
|
||||
}
|
||||
|
||||
async fetchWithCookies(url, options) {
|
||||
const cookieHeader = this.getCookieHeader();
|
||||
const headers = { ...options.headers, Cookie: cookieHeader };
|
||||
|
||||
const response = await fetchv2(url, headers );
|
||||
|
||||
const setCookieHeader = response.headers["Set-Cookie"];
|
||||
if (setCookieHeader) {
|
||||
this.storeCookies(setCookieHeader);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
isDdosGuard(response) {
|
||||
const serverHeader = response.headers["Server"];
|
||||
return serverHeader && this.serverCheck.includes(serverHeader.toLowerCase());
|
||||
}
|
||||
|
||||
async isBlockedResponse(response) {
|
||||
if (this.errorCodes.includes(response.status)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const clonedResponse = response.clone();
|
||||
const text = await clonedResponse.text();
|
||||
|
||||
if (text.includes('ddos-guard/js-challenge') ||
|
||||
text.includes('DDoS-Guard') ||
|
||||
text.includes('data-ddg-origin')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
storeCookies(setCookieString) {
|
||||
const cookies = Array.isArray(setCookieString) ? setCookieString : [setCookieString];
|
||||
|
||||
cookies.forEach(cookieHeader => {
|
||||
const parts = cookieHeader.split(";");
|
||||
if (parts.length > 0) {
|
||||
const [key, value] = parts[0].split("=");
|
||||
if (key) {
|
||||
this.cookieStore[key.trim()] = value?.trim() || "";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getCookieHeader() {
|
||||
return Object.entries(this.cookieStore)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join("; ");
|
||||
}
|
||||
|
||||
async getNewCookie(targetUrl) {
|
||||
try {
|
||||
const wellKnownResponse = await fetchv2("https://check.ddos-guard.net/check.js");
|
||||
const wellKnownText = await wellKnownResponse.text();
|
||||
|
||||
const paths = wellKnownText.match(/['"](\/\.well-known\/ddos-guard\/[^'"]+)['"]/g);
|
||||
const checkPaths = wellKnownText.match(/['"]https:\/\/check\.ddos-guard\.net\/[^'"]+['"]/g);
|
||||
|
||||
if (!paths || paths.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const localPath = paths[0].replace(/['"]/g, '');
|
||||
|
||||
const match = targetUrl.match(/^(https?:\/\/[^\/]+)/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const baseUrl = match[1];
|
||||
|
||||
const localUrl = `${baseUrl}${localPath}`;
|
||||
|
||||
const localResponse = await fetchv2(localUrl, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
||||
'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
||||
'Referer': targetUrl
|
||||
}
|
||||
});
|
||||
|
||||
let setCookie = localResponse.headers["set-cookie"] ||
|
||||
localResponse.headers["Set-Cookie"] ||
|
||||
(localResponse.headers.raw && localResponse.headers.raw()['set-cookie']) ||
|
||||
(localResponse.headers.get && localResponse.headers.get('set-cookie'));
|
||||
if (setCookie) {
|
||||
this.storeCookies(setCookie);
|
||||
}
|
||||
|
||||
if (checkPaths && checkPaths.length > 0) {
|
||||
const checkUrl = checkPaths[0].replace(/['"]/g, '');
|
||||
|
||||
const checkResponse = await fetchv2(checkUrl, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
||||
'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
||||
'Referer': targetUrl
|
||||
}
|
||||
});
|
||||
|
||||
setCookie = checkResponse.headers["set-cookie"] ||
|
||||
checkResponse.headers["Set-Cookie"] ||
|
||||
(checkResponse.headers.raw && checkResponse.headers.raw()['set-cookie']) ||
|
||||
(checkResponse.headers.get && checkResponse.headers.get('set-cookie'));
|
||||
if (setCookie) {
|
||||
this.storeCookies(setCookie);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.cookieStore["__ddg2_"]) {
|
||||
return this.cookieStore["__ddg2_"];
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue