From 646ef128a8ad6e3ce75f086e347bea033014987a Mon Sep 17 00:00:00 2001 From: Shinei Nouzen <157171073+Shineii86@users.noreply.github.com> Date: Sat, 4 Jul 2026 15:48:23 +0530 Subject: [PATCH] fix: extractPages URL handling for mirror fallback - Fix bug where full URLs were passed to fetchWithMirror causing doubled URLs - Extract path from full URL before passing to mirror fallback - Fixes search, most-popular, new-release, newly-added, and az-list endpoints --- src/helper/extractPages.helper.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/helper/extractPages.helper.js b/src/helper/extractPages.helper.js index 147a87a..d20b3dc 100644 --- a/src/helper/extractPages.helper.js +++ b/src/helper/extractPages.helper.js @@ -33,9 +33,22 @@ import { fetchWithMirror } from "./mirror.helper.js"; */ const extractPages = async (url, page = 1) => { try { - const separator = url.includes("?") ? "&" : "?"; - const path = page > 1 ? `${url}${separator}page=${page}` : url; - const { data } = await fetchWithMirror(path); + // NOTE: Extract path from full URL if needed (e.g., "https://anikototv.to/filter" -> "/filter") + let path = url; + if (url.startsWith("http")) { + try { + const urlObj = new URL(url); + path = urlObj.pathname + urlObj.search; + } catch (e) { + // If URL parsing fails, try to extract path manually + const match = url.match(/https?:\/\/[^/]+(\/.*)/); + if (match) path = match[1]; + } + } + + const separator = path.includes("?") ? "&" : "?"; + const fullPath = page > 1 ? `${path}${separator}page=${page}` : path; + const { data } = await fetchWithMirror(fullPath); const $ = cheerio.load(data); return $; } catch (error) {