Jinman: Fix failed to load image (#3706)

This commit is contained in:
AlphaBoom 2024-06-23 16:27:53 +08:00 committed by Draff
parent bfbdf30ab9
commit b6cba48ba7
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 18 additions and 6 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Jinman Tiantang' extName = 'Jinman Tiantang'
extClass = '.Jinmantiantang' extClass = '.Jinmantiantang'
extVersionCode = 42 extVersionCode = 43
isNsfw = true isNsfw = true
} }

View File

@ -11,6 +11,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.InputStream import java.io.InputStream
import java.security.MessageDigest import java.security.MessageDigest
import java.util.zip.GZIPInputStream
import kotlin.math.floor import kotlin.math.floor
object ScrambledImageInterceptor : Interceptor { object ScrambledImageInterceptor : Interceptor {
@ -22,13 +23,24 @@ object ScrambledImageInterceptor : Interceptor {
val pathSegments = url.pathSegments val pathSegments = url.pathSegments
val aid = pathSegments[pathSegments.size - 2].toInt() val aid = pathSegments[pathSegments.size - 2].toInt()
if (aid < scrambleId) return response // 对在漫画章节ID为220980之前的图片未进行图片分割,直接放行 if (aid < scrambleId) return response // 对在漫画章节ID为220980之前的图片未进行图片分割,直接放行
// 章节ID:220980(包含)之后的漫画(2020.10.27之后)图片进行了分割getRows倒序处理 // 章节ID:220980(包含)之后的漫画(2020.10.27之后)图片进行了分割getRows倒序处理
val responseBuilder = response.newBuilder()
val imgIndex: String = pathSegments.last().substringBefore('.') val imgIndex: String = pathSegments.last().substringBefore('.')
val res = response.body.byteStream().use { val input = if ("gzip" == response.header("Content-Encoding")) {
decodeImage(it, getRows(aid, imgIndex)) responseBuilder.headers(
response.headers.newBuilder()
.removeAll("Content-Encoding")
.removeAll("Content-Length")
.build(),
)
GZIPInputStream(response.body.byteStream())
} else {
response.body.byteStream()
} }
val outputBytes = res.toResponseBody(jpegMediaType) val newBody = input.use {
return response.newBuilder().body(outputBytes).build() decodeImage(it, getRows(aid, imgIndex))
}.toResponseBody(jpegMediaType)
return responseBuilder.body(newBody).build()
} }
// 220980 // 220980