import { ScraperError } from "../types" ; import fetch from "node-fetch-extra" ; param status param err export function error ( status = - 1 , err = "Unknown" ) { return { status , err , success : false } ; } export async function getDataFromURL ( url ) { let retryCount = 0 ; let isValid = false ; let data = { } ; while ( ! isValid && retryCount < 4 ) { const dataReq = await fetch ( url ) ; if ( dataReq . status === 204 ) { isValid = true ; return data ; } else { let res = ( data = await dataReq . text ( ) ) ; if ( ! res . startsWith ( "<" ) && res . trim ( ) . length > 0 ) { try { data = JSON . parse ( data ) ; isValid = true ; } catch ( e ) { retryCount ++ ; await sleep ( 100 * Math . floor ( Math . random ( ) * 50 ) ) ; } } else { retryCount ++ ; await sleep ( 100 * Math . floor ( Math . random ( ) * 50 ) ) ; } } } return data ; } function sleep ( ms ) { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; } import MangaseeInstance from "./mangasee" ; export const Mangasee = MangaseeInstance ; import RCOInstance from "./rco" ; export const RCO = RCOInstance ; import ManganeloInstance from "./manganelo" ; export const Manganelo = ManganeloInstance ; import ComicExtraInstance from "./comicextra" ; export const ComicExtra = ComicExtraInstance ; import nhentaiInstance from "./nhentai" ; export const nhentai = nhentaiInstance ; import nhentainetInstance from "./nhentainet" ; export const nhentainet = nhentainetInstance ; import MangahereInstance from "./mangahere" ; export const Mangahere = MangahereInstance ; import MangadexInstance from "./mangadex-v5" ; export const Mangadex5 = MangadexInstance ; import GuyaInstance from "./guya" ; export const Guya = GuyaInstance ; export const scrapers = { Mangasee , Mangadex5 , Manganelo , Mangahere , RCO , ComicExtra , nhentai , nhentainet , Guya } ;