RC: Fix webview partially (#2744)

* Fix webview

* Keep header in apiRequest
This commit is contained in:
bapeey 2024-05-03 05:31:06 -05:00 committed by Draff
parent 82ddc7daab
commit 0d7c58d326
2 changed files with 19 additions and 1 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.RizzComic'
themePkg = 'mangathemesia'
baseUrl = 'https://rizzfables.com'
overrideVersionCode = 3
overrideVersionCode = 4
}
apply from: "$rootDir/common.gradle"

View File

@ -31,11 +31,24 @@ class RizzComic : MangaThemesiaAlt(
override val client = super.client.newBuilder()
.rateLimit(1, 3)
.addInterceptor { chain ->
val request = chain.request()
val isApiRequest = request.header("X-API-Request") != null
val headers = request.headers.newBuilder().apply {
if (!isApiRequest) removeAll("X-Requested-With")
removeAll("X-API-Request")
}.build()
chain.proceed(request.newBuilder().headers(headers).build())
}
.build()
override fun headersBuilder() = super.headersBuilder()
.set("X-Requested-With", randomString((1..20).random())) // For WebView
private val apiHeaders by lazy {
headersBuilder()
.set("X-Requested-With", "XMLHttpRequest")
.set("X-API-Request", "1")
.build()
}
@ -154,4 +167,9 @@ class RizzComic : MangaThemesiaAlt(
it.toString()
}
}
private fun randomString(length: Int): String {
val charPool = ('a'..'z') + ('A'..'Z')
return List(length) { charPool.random() }.joinToString("")
}
}