Tappytoon: fix image downloads (#10710)
This commit is contained in:
parent
93593a29f1
commit
9f83a8a6ee
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'Tappytoon'
|
||||
pkgNameSuffix = 'all.tappytoon'
|
||||
extClass = '.TappytoonFactory'
|
||||
extVersionCode = 4
|
||||
extVersionCode = 5
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,16 @@ class Tappytoon(override val lang: String) : HttpSource() {
|
|||
|
||||
override val client = network.client.newBuilder().addInterceptor { chain ->
|
||||
val res = chain.proceed(chain.request())
|
||||
if (res.isSuccessful) return@addInterceptor res
|
||||
val mime = res.headers["Content-Type"]
|
||||
if (res.isSuccessful) {
|
||||
if (mime != "application/octet-stream")
|
||||
return@addInterceptor res
|
||||
// Fix Content-Type header
|
||||
return@addInterceptor res.newBuilder()
|
||||
.header("Content-Type", "image/jpeg").build()
|
||||
}
|
||||
// Throw JSON error if available
|
||||
if (res.headers["Content-Type"] == "application/json") {
|
||||
if (mime == "application/json") {
|
||||
res.body?.string()?.let(json::parseToJsonElement)?.run {
|
||||
throw Error(jsonObject["message"]!!.jsonPrimitive.content)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue