From 159c9ca8aa86ebc8545b210d77e0e83a7871eefa Mon Sep 17 00:00:00 2001 From: Shinei Nouzen <157171073+Shineii86@users.noreply.github.com> Date: Wed, 29 Jul 2026 02:16:13 +0530 Subject: [PATCH] fix: Episodes Ajax test, strip quotes from server_ids, dynamic stream resolve setup --- src/extractors/episodeList.extractor.js | 2 +- src/extractors/episodeListAjax.extractor.js | 2 +- test.js | 40 ++++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/extractors/episodeList.extractor.js b/src/extractors/episodeList.extractor.js index 153cdbd..e4da435 100644 --- a/src/extractors/episodeList.extractor.js +++ b/src/extractors/episodeList.extractor.js @@ -74,7 +74,7 @@ const extractEpisodeList = async (slugOrId) => { const href = $ep(el).attr("href") || ""; const epTitle = $ep(el).find(".ep-title, .ep-name").text().trim() || ""; const isActive = $ep(el).hasClass("active") || false; - const serverIds = $ep(el).attr("data-ids") || ""; + const serverIds = ($ep(el).attr("data-ids") || "").replace(/^\\?["']|\\?["']$/g, ""); const timestamp = $ep(el).attr("data-timestamp") || ""; const malId = $ep(el).attr("data-mal") || ""; diff --git a/src/extractors/episodeListAjax.extractor.js b/src/extractors/episodeListAjax.extractor.js index 078523f..ad5570b 100644 --- a/src/extractors/episodeListAjax.extractor.js +++ b/src/extractors/episodeListAjax.extractor.js @@ -98,7 +98,7 @@ const extractEpisodeListAjax = async (animeId, style = "", vrf = "") => { timestamp: a.attr("data-timestamp") || "", has_sub: a.attr("data-sub") === "1", has_dub: a.attr("data-dub") === "1", - server_ids: a.attr("data-ids") || "", + server_ids: (a.attr("data-ids") || "").replace(/^\\?["']|\\?["']$/g, ""), active: a.hasClass("active") || false }); }); diff --git a/test.js b/test.js index 4689d32..9239fab 100644 --- a/test.js +++ b/test.js @@ -24,7 +24,7 @@ const tests = [ { name: "Servers", url: "/servers?ids=1", check: (d) => d.results }, // Streaming { name: "Stream", url: "/watch?slug=one-piece-odmau&ep=1", check: (d) => d.results?.servers || d.results?.episodeNumber }, - { name: "Stream Resolve", url: "/stream/resolve?id=MTF1dkFtaW9BRTZPbzJJRElFZUZrNHVJWFRVWWRWdU5JYnhuaU95bVRYSzk1Z0lVVjJha2FnSE95U3F4M1RsaXNCSnlnd05rTTlBUldTZGZxZjQzajVxcXVDRVY5bjBocnRCV2tkNnNzaXFnc3c5M1JJWjRnNmt5bDNPdm1TczlvVXdwWGplKzFmQmZJMlp0OTBNTXd3PT0&slug=one-piece-odmau", check: (d) => d.results?.url, optional: true }, + // Discovery endpoints { name: "Suggestions", url: "/suggestions?keyword=naruto", check: (d) => d.results }, @@ -52,7 +52,6 @@ const tests = [ // Search variants { name: "Search Suggest", url: "/search/suggest?keyword=naruto", check: (d) => d.results }, - { name: "Episodes Ajax", url: "/episodes-ajax/one-piece-odmau", check: (d) => d.results, optional: true }, { name: "Trending Sidebar", url: "/trending-sidebar", check: (d) => d.results }, // Anime detail @@ -142,11 +141,44 @@ async function runTest(test) { } } +async function fetchJson(url) { + const res = await fetch(`${BASE}${url}`); + return res.ok ? res.json() : null; +} + async function runAll() { console.log(`\n🧪 Running ${tests.length} tests...\n`); console.log(`📡 API: ${BASE}\n`); - - // Run tests sequentially to avoid rate limiting + + // ---- FEATURE: Resolve dynamic test dependencies ---- + // NOTE: Fetch info to get numeric animeId for episodes-ajax + let animeId = "1642"; + let linkId = ""; + try { + const info = await fetchJson("/info?id=one-piece-odmau"); + if (info?.success && info.results?.animeId) { + animeId = info.results.animeId; + } + // NOTE: Get a valid link_id via episodes → servers flow + const epData = await fetchJson("/episodes/one-piece-odmau"); + if (epData?.success && epData.results?.episodes?.length > 0) { + const sid = epData.results.episodes[0].server_ids; + if (sid) { + const srvData = await fetchJson(`/servers?ids=${encodeURIComponent(sid)}`); + if (srvData?.success && srvData.results?.length > 0) { + linkId = srvData.results[0].link_id || ""; + } + } + } + } catch (_) { /* use defaults */ } + + // ---- FEATURE: Inject dynamic tests with live data ---- + tests.push({ name: "Episodes Ajax", url: `/episodes-ajax/${animeId}`, check: (d) => d.results?.episodes || d.results?.totalEpisodes }); + if (linkId) { + tests.push({ name: "Stream Resolve", url: `/stream/resolve?id=${encodeURIComponent(linkId)}&slug=one-piece-odmau`, check: (d) => d.results?.url }); + } + + // ---- FEATURE: Run all tests sequentially ---- for (const test of tests) { await runTest(test); }