snowmtl: fix image intercept (#6529)

This commit is contained in:
Cuong-Tran 2024-12-08 20:14:17 +07:00 committed by Draff
parent 7abb7e3c16
commit e11aafbd0f
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Snow Machine Translations'
extClass = '.Snowmtl'
extVersionCode = 2
extVersionCode = 3
isNsfw = true
}

View File

@ -32,7 +32,7 @@ import kotlin.math.sqrt
// The Interceptor joins the captions and pages of the manga.
@RequiresApi(Build.VERSION_CODES.O)
class ComposedImageInterceptor(
private val baseUrl: String,
baseUrl: String,
private val client: OkHttpClient,
) : Interceptor {
@ -44,11 +44,16 @@ class ComposedImageInterceptor(
"normal" to Pair<String, Typeface?>("$baseUrl/images/normal.ttf", null),
)
private val imageRegex = Regex(
"$baseUrl.*?\\.(webp|png|jpg|jpeg)#\\[.*?]",
RegexOption.IGNORE_CASE,
)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val url = request.url.toString()
val isPageImageUrl = url.contains("${baseUrl.substringAfterLast("/")}/storage/", true)
val isPageImageUrl = imageRegex.containsMatchIn(url)
if (isPageImageUrl.not()) {
return chain.proceed(request)
}