Xinmeitulu: intercept to fix media type of image response body (#11999)
* Xinmeitulu: intercept to fix media type of image response body * Move interceptor into companion object
This commit is contained in:
parent
c6d4f5c99c
commit
c388889e02
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'Xinmeitulu'
|
extName = 'Xinmeitulu'
|
||||||
pkgNameSuffix = 'all.xinmeitulu'
|
pkgNameSuffix = 'all.xinmeitulu'
|
||||||
extClass = '.Xinmeitulu'
|
extClass = '.Xinmeitulu'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.ResponseBody.Companion.asResponseBody
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
@ -19,6 +23,8 @@ class Xinmeitulu : ParsedHttpSource() {
|
||||||
override val name = "Xinmeitulu"
|
override val name = "Xinmeitulu"
|
||||||
override val supportsLatest = false
|
override val supportsLatest = false
|
||||||
|
|
||||||
|
override val client = network.client.newBuilder().addInterceptor(::contentTypeIntercept).build()
|
||||||
|
|
||||||
// Latest
|
// Latest
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException("Not Used.")
|
override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException("Not Used.")
|
||||||
|
@ -79,4 +85,17 @@ class Xinmeitulu : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
|
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private fun contentTypeIntercept(chain: Interceptor.Chain): Response {
|
||||||
|
val response = chain.proceed(chain.request())
|
||||||
|
if (response.header("content-type")?.startsWith("image") == true) {
|
||||||
|
val body = response.body!!.source().asResponseBody(jpegMediaType)
|
||||||
|
return response.newBuilder().body(body).build()
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
private val jpegMediaType = "image/jpeg".toMediaType()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue