From 8e610e1ea9783a4c78e702a2a0bbe3edd665acd3 Mon Sep 17 00:00:00 2001 From: Secozzi <49240133+Secozzi@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:54:26 +0000 Subject: [PATCH] Infinityscans: fix cloudflare issues (#1067) fix cloudflare issues --- src/en/infinityscans/build.gradle | 2 +- .../en/infinityscans/InfinityScans.kt | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/en/infinityscans/build.gradle b/src/en/infinityscans/build.gradle index 381161322..14e5e073d 100644 --- a/src/en/infinityscans/build.gradle +++ b/src/en/infinityscans/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'InfinityScans' extClass = '.InfinityScans' - extVersionCode = 3 + extVersionCode = 4 isNsfw = true } diff --git a/src/en/infinityscans/src/eu/kanade/tachiyomi/extension/en/infinityscans/InfinityScans.kt b/src/en/infinityscans/src/eu/kanade/tachiyomi/extension/en/infinityscans/InfinityScans.kt index b879b3901..3b07992da 100644 --- a/src/en/infinityscans/src/eu/kanade/tachiyomi/extension/en/infinityscans/InfinityScans.kt +++ b/src/en/infinityscans/src/eu/kanade/tachiyomi/extension/en/infinityscans/InfinityScans.kt @@ -40,8 +40,17 @@ class InfinityScans : HttpSource() { .rateLimit(1) .build() - override fun headersBuilder() = super.headersBuilder() - .add("Referer", "$baseUrl/") + override fun headersBuilder() = super.headersBuilder().apply { + add("Referer", "$baseUrl/") + } + + private val apiHeaders = headersBuilder().apply { + add("Accept", "*/*") + add("Sec-Fetch-Dest", "empty") + add("Sec-Fetch-Mode", "cors") + add("Sec-Fetch-Site", "same-origin") + add("X-Requested-With", "XMLHttpRequest") + }.build() private val json: Json by injectLazy() @@ -64,10 +73,6 @@ class InfinityScans : HttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val searchHeaders = headersBuilder().apply { - add("X-Requested-With", "XMLHttpRequest") - }.build() - val url = baseUrl.toHttpUrl().newBuilder() .addPathSegments("ajax/comics") .addQueryParameter("page", page.toString()) @@ -98,6 +103,10 @@ class InfinityScans : HttpSource() { if (query.isNotBlank()) url.addQueryParameter("title", query) + val searchHeaders = apiHeaders.newBuilder().apply { + set("Referer", url.build().newBuilder().removePathSegment(0).build().toString()) + }.build() + return GET(url.build(), searchHeaders) } @@ -206,13 +215,11 @@ class InfinityScans : HttpSource() { add("comic_id", id) }.build() - val chapterHeaders = headersBuilder().apply { - add("Accept", "*/*") + val chapterHeaders = apiHeaders.newBuilder().apply { add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") add("Host", baseUrl.toHttpUrl().host) add("Origin", baseUrl) set("Referer", url.toString()) - add("X-Requested-With", "XMLHttpRequest") }.build() val chapterListData = client.newCall( @@ -249,12 +256,10 @@ class InfinityScans : HttpSource() { ) }.build() - val pageListHeaders = headersBuilder().apply { - add("Accept", "*/*") + val pageListHeaders = apiHeaders.newBuilder().apply { add("Host", url.host) add("Origin", baseUrl) set("Referer", url.toString()) - add("X-Requested-With", "XMLHttpRequest") }.build() val pageListData = client.newCall(