Tappytoon: fix image content type (#11086)

This commit is contained in:
ObserverOfTime 2022-03-12 23:56:16 +02:00 committed by GitHub
parent 28bbcb3612
commit 55fe02563c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

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

View File

@ -14,8 +14,10 @@ import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
@ -34,9 +36,11 @@ class Tappytoon(override val lang: String) : HttpSource() {
if (res.isSuccessful) { if (res.isSuccessful) {
if (mime != "application/octet-stream") if (mime != "application/octet-stream")
return@addInterceptor res return@addInterceptor res
// Fix Content-Type header // Fix image content type
return@addInterceptor res.newBuilder() val type = IMG_CONTENT_TYPE.toMediaType()
.header("Content-Type", "image/jpeg").build() val body = res.body!!.bytes().toResponseBody(type)
return@addInterceptor res.newBuilder().body(body)
.header("Content-Type", IMG_CONTENT_TYPE).build()
} }
// Throw JSON error if available // Throw JSON error if available
if (mime == "application/json") { if (mime == "application/json") {
@ -199,6 +203,8 @@ class Tappytoon(override val lang: String) : HttpSource() {
throw UnsupportedOperationException("Not used") throw UnsupportedOperationException("Not used")
companion object { companion object {
private const val IMG_CONTENT_TYPE = "image/jpeg"
private val apiUrl = "https://api-global.tappytoon.com".toHttpUrl() private val apiUrl = "https://api-global.tappytoon.com".toHttpUrl()
private val genres = mapOf( private val genres = mapOf(