From 04a60a51eb8e4d71c1f616d1ce85782c4dc07f07 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Wed, 22 May 2024 00:41:15 -0500 Subject: [PATCH] Manhastro: fix downloads (#3171) fix --- src/pt/manhastro/build.gradle | 2 +- .../extension/pt/manhastro/Manhastro.kt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pt/manhastro/build.gradle b/src/pt/manhastro/build.gradle index cefc639c5..e63d04c79 100644 --- a/src/pt/manhastro/build.gradle +++ b/src/pt/manhastro/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.Manhastro' themePkg = 'madara' baseUrl = 'https://manhastro.com' - overrideVersionCode = 4 + overrideVersionCode = 5 isNsfw = true } diff --git a/src/pt/manhastro/src/eu/kanade/tachiyomi/extension/pt/manhastro/Manhastro.kt b/src/pt/manhastro/src/eu/kanade/tachiyomi/extension/pt/manhastro/Manhastro.kt index 68924ff63..e2838e213 100644 --- a/src/pt/manhastro/src/eu/kanade/tachiyomi/extension/pt/manhastro/Manhastro.kt +++ b/src/pt/manhastro/src/eu/kanade/tachiyomi/extension/pt/manhastro/Manhastro.kt @@ -5,7 +5,9 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.source.model.Page import kotlinx.serialization.decodeFromString +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient +import okhttp3.ResponseBody.Companion.toResponseBody import org.jsoup.nodes.Document import java.text.SimpleDateFormat import java.util.Locale @@ -20,6 +22,21 @@ class Manhastro : Madara( override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) + .addInterceptor { chain -> + val response = chain.proceed(chain.request()) + val mime = response.headers["Content-Type"] + if (response.isSuccessful) { + if (mime != "application/octet-stream") { + return@addInterceptor response + } + // Fix image content type + val type = IMG_CONTENT_TYPE.toMediaType() + val body = response.body.bytes().toResponseBody(type) + return@addInterceptor response.newBuilder().body(body) + .header("Content-Type", IMG_CONTENT_TYPE).build() + } + response + } .build() override val useNewChapterEndpoint = true @@ -39,4 +56,8 @@ class Manhastro : Madara( } private val imageLinksPattern = """var\s+?imageLinks\s*?=\s*?(\[.*]);""".toRegex() + + companion object { + private const val IMG_CONTENT_TYPE = "image/jpeg" + } }