Bainian Manhua: fix image MIME (#12641)

This commit is contained in:
stevenyomi 2022-07-21 10:34:42 +08:00 committed by GitHub
parent 4807058f0e
commit 4e30c58623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Bainian Manhua'
pkgNameSuffix = 'zh.bainianmanga'
extClass = '.Bainian'
extVersionCode = 7
extVersionCode = 8
}
apply from: "$rootDir/common.gradle"

View File

@ -16,7 +16,6 @@ import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
@ -41,7 +40,10 @@ class Bainian : ParsedHttpSource(), ConfigurableSource {
private fun String.stripMirror() = if (useMirror) "/comic" + removePrefix("/manhuadaquan") else this
private fun String.toMirror() = if (useMirror) baseUrl + "/manhuadaquan" + removePrefix("/comic") else baseUrl + this
override val client: OkHttpClient = network.client.newBuilder().rateLimit(2).build()
override val client = network.client.newBuilder()
.rateLimit(2)
.addInterceptor(MimeInterceptor)
.build()
override fun popularMangaRequest(page: Int) = GET("$baseUrl/page/hot/$page.html", headers)
override fun popularMangaNextPageSelector() = ".pagination > li:last-child > a"
@ -191,10 +193,6 @@ class Bainian : ParsedHttpSource(), ConfigurableSource {
title = "使用镜像网站"
summary = "使用“漫画全集”网站,重启生效"
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
preferences.edit().putBoolean(USE_MIRROR_PREF, newValue as Boolean).apply()
true
}
}.let { screen.addPreference(it) }
}

View File

@ -0,0 +1,22 @@
package eu.kanade.tachiyomi.extension.zh.bainianmanga
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Response
import okhttp3.ResponseBody.Companion.asResponseBody
object MimeInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val response = chain.proceed(request)
if (response.header("Content-Type") == "application/octet-stream" &&
request.url.toString().contains(".jpg")
) {
val body = response.body!!.source().asResponseBody(jpegMime)
return response.newBuilder().body(body).build()
}
return response
}
private val jpegMime = "image/jpeg".toMediaType()
}