tt
Fetch and Save Remote Content / fetch (push) Failing after 11m43s

This commit is contained in:
aka paul
2026-06-03 18:12:40 +02:00
parent b49d770f57
commit 887ee54145
+11 -23
View File
@@ -1,6 +1,5 @@
let cachedAuthKey = null;
let cachedAuthExpires = 0;
let cachedCookie = null;
async function getFingerprint() {
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
@@ -57,9 +56,9 @@ function Ks(method, urlPath, clientAuthKey) {
};
}
async function getAuthKeyAndCookie() {
if (cachedAuthKey && cachedCookie && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
return { authKey: cachedAuthKey, cookie: cachedCookie };
async function getAuthKey() {
if (cachedAuthKey && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
return cachedAuthKey;
}
const fp = await getFingerprint();
const sessionRes = await fetchv2(
@@ -68,43 +67,32 @@ async function getAuthKeyAndCookie() {
'POST',
JSON.stringify({ fp })
);
const sessionText = await sessionRes.text();
const sessionText = typeof sessionRes.text === 'function' ? await sessionRes.text() : sessionRes;
const sessionData = JSON.parse(sessionText);
if (!sessionData.clientAuthKey) {
throw new Error("Session bootstrap failed: " + sessionText);
}
let setCookie = null;
if (sessionRes.headers) {
if (typeof sessionRes.headers.get === 'function') {
setCookie = sessionRes.headers.get('set-cookie');
} else {
setCookie = sessionRes.headers['set-cookie'] || sessionRes.headers['Set-Cookie'];
}
}
cachedAuthKey = sessionData.clientAuthKey;
cachedAuthExpires = sessionData.expiresAt - 10;
cachedCookie = setCookie ? setCookie.split(';')[0] : null;
return { authKey: cachedAuthKey, cookie: cachedCookie };
return cachedAuthKey;
}
async function fetchSigned(urlPath) {
const { authKey, cookie } = await getAuthKeyAndCookie();
const authKey = await getAuthKey();
const sigHeaders = Ks('GET', urlPath, authKey);
const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0',
'x-av-ts': sigHeaders['x-av-ts'],
'x-av-sig': sigHeaders['x-av-sig']
};
if (cookie) {
headers['cookie'] = cookie;
}
return await fetchv2(`https://animeverse.to${urlPath}`, headers, 'GET');
}
async function searchResults(keyword) {
try {
const response = await fetchSigned('/api/v1/catalog');
const text = await response.text();
const text = typeof response.text === 'function' ? await response.text() : response;
const data = JSON.parse(text);
const kw = typeof keyword === 'string' ? keyword : '';
@@ -161,7 +149,7 @@ async function extractDetails(url) {
try {
const slug = url.split('/').pop();
const response = await fetchSigned(`/api/v1/anime/${slug}`);
const text = await response.text();
const text = typeof response.text === 'function' ? await response.text() : response;
const data = JSON.parse(text);
return JSON.stringify([{
@@ -182,7 +170,7 @@ async function extractEpisodes(url) {
try {
const slug = url.split('/').pop();
const response = await fetchSigned(`/api/v1/anime/${slug}`);
const text = await response.text();
const text = typeof response.text === 'function' ? await response.text() : response;
const data = JSON.parse(text);
const results = (data.episodes || []).map(ep => ({
@@ -206,7 +194,7 @@ async function extractStreamUrl(url) {
const slug = parts.pop();
const response = await fetchSigned(`/api/v1/anime/${slug}/stream/${episodeNumber}`);
const text = await response.text();
const text = typeof response.text === 'function' ? await response.text() : response;
const data = JSON.parse(text);
return data.stream || "https://error.org/";