From 01e27823f6a4afc77bcdf245ad97497a33d01658 Mon Sep 17 00:00:00 2001 From: beerpsi <92439990+beerpiss@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:39:09 +0700 Subject: [PATCH] Mangas Chan: Fix Cloudflare block (#637) * Mangas Chan: Fix Cloudflare block * Add an interceptor to remove X-Requested-With * use CharArray instead of List Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> --------- Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> --- .../mangathemesia/mangaschan/src/MangasChan.kt | 16 ++++++++++++++++ .../mangathemesia/MangaThemesiaGenerator.kt | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt b/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt index 9f0dfe835..fc801bc76 100644 --- a/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt +++ b/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt @@ -15,12 +15,28 @@ class MangasChan : MangaThemesia( ) { override val client: OkHttpClient = super.client.newBuilder() + .addInterceptor { chain -> + val request = chain.request() + val headers = request.headers.newBuilder() + .removeAll("X-Requested-With") + .build() + + chain.proceed(request.newBuilder().headers(headers).build()) + } .rateLimit(1, 2, TimeUnit.SECONDS) .build() + override fun headersBuilder() = super.headersBuilder() + .set("X-Requested-With", randomString((10..20).random())) + override val altNamePrefix = "Nomes alternativos: " override val seriesArtistSelector = ".tsinfo .imptdt:contains(Artista) > i" override val seriesAuthorSelector = ".tsinfo .imptdt:contains(Autor) > i" override val seriesTypeSelector = ".tsinfo .imptdt:contains(Tipo) > a" + + private fun randomString(length: Int): String { + val charPool = ('a'..'z') + ('A'..'Z') + return CharArray(length) { charPool.random() }.concatToString() + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt index 3c83fddb1..949366f31 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt @@ -91,7 +91,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator { SingleLang("MangaTale", "https://mangatale.co", "id", overrideVersionCode = 2), SingleLang("MangaWT", "https://mangawt.com", "tr", overrideVersionCode = 5), SingleLang("Mangayaro", "https://www.mangayaro.id", "id", overrideVersionCode = 1), - SingleLang("Mangás Chan", "https://mangaschan.net", "pt-BR", className = "MangasChan", overrideVersionCode = 2), + SingleLang("Mangás Chan", "https://mangaschan.net", "pt-BR", className = "MangasChan", overrideVersionCode = 3), SingleLang("Mangás Online", "https://mangasonline.cc", "pt-BR", className = "MangasOnline"), SingleLang("Manhwa Freak", "https://manhwa-freak.com", "en", overrideVersionCode = 3), SingleLang("Manhwa Lover", "https://manhwalover.com", "en", isNsfw = true, overrideVersionCode = 1),