mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
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
This commit is contained in:
@@ -33,9 +33,22 @@ import { fetchWithMirror } from "./mirror.helper.js";
|
|||||||
*/
|
*/
|
||||||
const extractPages = async (url, page = 1) => {
|
const extractPages = async (url, page = 1) => {
|
||||||
try {
|
try {
|
||||||
const separator = url.includes("?") ? "&" : "?";
|
// NOTE: Extract path from full URL if needed (e.g., "https://anikototv.to/filter" -> "/filter")
|
||||||
const path = page > 1 ? `${url}${separator}page=${page}` : url;
|
let path = url;
|
||||||
const { data } = await fetchWithMirror(path);
|
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);
|
const $ = cheerio.load(data);
|
||||||
return $;
|
return $;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user