This commit is contained in:
+27
-14
@@ -1,5 +1,6 @@
|
|||||||
let cachedAuthKey = null;
|
let cachedAuthKey = null;
|
||||||
let cachedAuthExpires = 0;
|
let cachedAuthExpires = 0;
|
||||||
|
let authKeyPromise = null;
|
||||||
|
|
||||||
async function getFingerprint() {
|
async function getFingerprint() {
|
||||||
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
|
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
|
||||||
@@ -60,22 +61,34 @@ async function getAuthKey() {
|
|||||||
if (cachedAuthKey && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
|
if (cachedAuthKey && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
|
||||||
return cachedAuthKey;
|
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;
|
if (authKeyPromise) {
|
||||||
const sessionData = JSON.parse(sessionText);
|
return authKeyPromise;
|
||||||
if (!sessionData.clientAuthKey) {
|
|
||||||
throw new Error("Session bootstrap failed: " + sessionText);
|
|
||||||
}
|
}
|
||||||
cachedAuthKey = sessionData.clientAuthKey;
|
|
||||||
cachedAuthExpires = sessionData.expiresAt - 10;
|
authKeyPromise = (async () => {
|
||||||
return cachedAuthKey;
|
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) {
|
async function fetchSigned(urlPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user