Tappytoon: fix image downloads (#10710)

This commit is contained in:
ObserverOfTime 2022-02-05 19:44:44 +02:00 committed by GitHub
parent 93593a29f1
commit 9f83a8a6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tappytoon'
pkgNameSuffix = 'all.tappytoon'
extClass = '.TappytoonFactory'
extVersionCode = 4
extVersionCode = 5
isNsfw = true
}

View File

@ -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)
}