This commit is contained in:
+27
-14
@@ -1,5 +1,6 @@
|
||||
let cachedAuthKey = null;
|
||||
let cachedAuthExpires = 0;
|
||||
let authKeyPromise = null;
|
||||
|
||||
async function getFingerprint() {
|
||||
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
|
||||
@@ -60,22 +61,34 @@ async function getAuthKey() {
|
||||
if (cachedAuthKey && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
|
||||
return cachedAuthKey;
|
||||
}
|
||||
const fp = await getFingerprint();
|
||||
const sessionRes = await fetchv2(
|
||||
'https://animeverse.to/api/v1/session',
|
||||
{ 'content-type': 'application/json', 'user-agent': fp.ua },
|
||||
'POST',
|
||||
JSON.stringify({ fp })
|
||||
);
|
||||
|
||||
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);
|
||||
if (authKeyPromise) {
|
||||
return authKeyPromise;
|
||||
}
|
||||
cachedAuthKey = sessionData.clientAuthKey;
|
||||
cachedAuthExpires = sessionData.expiresAt - 10;
|
||||
return cachedAuthKey;
|
||||
|
||||
authKeyPromise = (async () => {
|
||||
try {
|
||||
const fp = await getFingerprint();
|
||||
const sessionRes = await fetchv2(
|
||||
'https://animeverse.to/api/v1/session',
|
||||
{ 'content-type': 'application/json', 'user-agent': fp.ua },
|
||||
'POST',
|
||||
JSON.stringify({ fp })
|
||||
);
|
||||
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);
|
||||
}
|
||||
cachedAuthKey = sessionData.clientAuthKey;
|
||||
cachedAuthExpires = sessionData.expiresAt - 10;
|
||||
return cachedAuthKey;
|
||||
} finally {
|
||||
authKeyPromise = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return authKeyPromise;
|
||||
}
|
||||
|
||||
async function fetchSigned(urlPath) {
|
||||
|
||||
Reference in New Issue
Block a user