From 0e0682ffafff172b2f9a55b5992b1df73b2e9e6e Mon Sep 17 00:00:00 2001 From: aka paul <80717571+50n50@users.noreply.github.com> Date: Wed, 3 Jun 2026 18:21:26 +0200 Subject: [PATCH] ngl idk what it did, might be big --- animeverse/animeverse.js | 41 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/animeverse/animeverse.js b/animeverse/animeverse.js index 7e5d728..d4e1177 100644 --- a/animeverse/animeverse.js +++ b/animeverse/animeverse.js @@ -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) {