TsukiMangas: Fix (#4295)
* Fix content loading for the logged-in user * Some changes * Remove annotation * Remove unneeded code * Fix indentation * Add suppress lint * Enable blockNetworkImage Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> --------- Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com>
This commit is contained in:
parent
ee3d182a5f
commit
d07fbd5294
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Tsuki Mangás'
|
extName = 'Tsuki Mangás'
|
||||||
extClass = '.TsukiMangas'
|
extClass = '.TsukiMangas'
|
||||||
extVersionCode = 5
|
extVersionCode = 6
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package eu.kanade.tachiyomi.extension.pt.tsukimangas
|
package eu.kanade.tachiyomi.extension.pt.tsukimangas
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Application
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.webkit.WebViewClient
|
||||||
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.ChapterListDto
|
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.ChapterListDto
|
||||||
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.CompleteMangaDto
|
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.CompleteMangaDto
|
||||||
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.MangaListDto
|
import eu.kanade.tachiyomi.extension.pt.tsukimangas.dto.MangaListDto
|
||||||
|
@ -22,9 +28,13 @@ import okhttp3.Interceptor
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class TsukiMangas : HttpSource() {
|
class TsukiMangas : HttpSource() {
|
||||||
|
|
||||||
|
@ -38,6 +48,41 @@ class TsukiMangas : HttpSource() {
|
||||||
|
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
|
|
||||||
|
@delegate:SuppressLint("SetJavaScriptEnabled")
|
||||||
|
private val token: String by lazy {
|
||||||
|
val latch = CountDownLatch(1)
|
||||||
|
var token = ""
|
||||||
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
val webView = WebView(Injekt.get<Application>())
|
||||||
|
with(webView.settings) {
|
||||||
|
javaScriptEnabled = true
|
||||||
|
domStorageEnabled = true
|
||||||
|
databaseEnabled = true
|
||||||
|
blockNetworkImage = true
|
||||||
|
}
|
||||||
|
webView.webViewClient = object : WebViewClient() {
|
||||||
|
override fun onPageFinished(view: WebView, url: String) {
|
||||||
|
val script = "javascript:localStorage['token']"
|
||||||
|
view.evaluateJavascript(script) {
|
||||||
|
view.apply {
|
||||||
|
stopLoading()
|
||||||
|
destroy()
|
||||||
|
}
|
||||||
|
if (it.isBlank() || it in listOf("null", "undefined")) {
|
||||||
|
return@evaluateJavascript
|
||||||
|
}
|
||||||
|
token = it.replace("[\"]+".toRegex(), "")
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webView.loadUrl(baseUrl)
|
||||||
|
}
|
||||||
|
latch.await(10, TimeUnit.SECONDS)
|
||||||
|
|
||||||
|
token
|
||||||
|
}
|
||||||
|
|
||||||
override val client by lazy {
|
override val client by lazy {
|
||||||
network.client.newBuilder()
|
network.client.newBuilder()
|
||||||
.addInterceptor(::apiHeadersInterceptor)
|
.addInterceptor(::apiHeadersInterceptor)
|
||||||
|
@ -213,7 +258,16 @@ class TsukiMangas : HttpSource() {
|
||||||
|
|
||||||
// ============================= Utilities ==============================
|
// ============================= Utilities ==============================
|
||||||
private inline fun <reified T> Response.parseAs(): T = use {
|
private inline fun <reified T> Response.parseAs(): T = use {
|
||||||
json.decodeFromStream(it.body.byteStream())
|
try {
|
||||||
|
json.decodeFromStream(it.body.byteStream())
|
||||||
|
} catch (_: Exception) {
|
||||||
|
throw Exception(
|
||||||
|
"""
|
||||||
|
Contéudo protegido ou foi removido.
|
||||||
|
Faça o login na WebView e tente novamente
|
||||||
|
""".trimIndent(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun HttpUrl.Builder.addIfNotBlank(query: String, value: String): HttpUrl.Builder {
|
private fun HttpUrl.Builder.addIfNotBlank(query: String, value: String): HttpUrl.Builder {
|
||||||
|
@ -284,6 +338,9 @@ class TsukiMangas : HttpSource() {
|
||||||
|
|
||||||
val newRequest = request.newBuilder().apply {
|
val newRequest = request.newBuilder().apply {
|
||||||
apiHeaders.entries.forEach { addHeader(it.key, it.value) }
|
apiHeaders.entries.forEach { addHeader(it.key, it.value) }
|
||||||
|
if (token.isNotBlank()) {
|
||||||
|
addHeader("Authorization", "Bearer $token")
|
||||||
|
}
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
return chain.proceed(newRequest)
|
return chain.proceed(newRequest)
|
||||||
|
|
Loading…
Reference in New Issue