Manhastro: fix downloads (#3171)

fix
This commit is contained in:
bapeey 2024-05-22 00:41:15 -05:00 committed by Draff
parent 0cbbe84fbb
commit 04a60a51eb
2 changed files with 22 additions and 1 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.Manhastro' extClass = '.Manhastro'
themePkg = 'madara' themePkg = 'madara'
baseUrl = 'https://manhastro.com' baseUrl = 'https://manhastro.com'
overrideVersionCode = 4 overrideVersionCode = 5
isNsfw = true isNsfw = true
} }

View File

@ -5,7 +5,9 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.ResponseBody.Companion.toResponseBody
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
@ -20,6 +22,21 @@ class Manhastro : Madara(
override val client: OkHttpClient = super.client.newBuilder() override val client: OkHttpClient = super.client.newBuilder()
.rateLimit(1, 2, TimeUnit.SECONDS) .rateLimit(1, 2, TimeUnit.SECONDS)
.addInterceptor { chain ->
val response = chain.proceed(chain.request())
val mime = response.headers["Content-Type"]
if (response.isSuccessful) {
if (mime != "application/octet-stream") {
return@addInterceptor response
}
// Fix image content type
val type = IMG_CONTENT_TYPE.toMediaType()
val body = response.body.bytes().toResponseBody(type)
return@addInterceptor response.newBuilder().body(body)
.header("Content-Type", IMG_CONTENT_TYPE).build()
}
response
}
.build() .build()
override val useNewChapterEndpoint = true override val useNewChapterEndpoint = true
@ -39,4 +56,8 @@ class Manhastro : Madara(
} }
private val imageLinksPattern = """var\s+?imageLinks\s*?=\s*?(\[.*]);""".toRegex() private val imageLinksPattern = """var\s+?imageLinks\s*?=\s*?(\[.*]);""".toRegex()
companion object {
private const val IMG_CONTENT_TYPE = "image/jpeg"
}
} }