Replace QuickJS with Nashorn (#4)
This commit is contained in:
@@ -34,7 +34,7 @@ dependencies {
|
||||
implementation("com.github.KotatsuApp:kotatsu-parsers:14cff0d651")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("com.squareup.okio:okio:3.11.0")
|
||||
implementation("io.webfolder:quickjs:1.1.0")
|
||||
implementation("org.openjdk.nashorn:nashorn-core:15.6")
|
||||
implementation("org.json:json:20240303")
|
||||
implementation("me.tongfei:progressbar:0.10.1")
|
||||
implementation("androidx.collection:collection:1.5.0")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.koitharu.kotatsu.dl.parsers
|
||||
|
||||
import com.koushikdutta.quack.QuackContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
import okhttp3.CookieJar
|
||||
@@ -17,11 +16,15 @@ import org.koitharu.kotatsu.parsers.util.requireBody
|
||||
import java.awt.image.BufferedImage
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.imageio.ImageIO
|
||||
import javax.script.ScriptEngineManager
|
||||
|
||||
|
||||
class MangaLoaderContextImpl : MangaLoaderContext() {
|
||||
|
||||
override val cookieJar: CookieJar = InMemoryCookieJar()
|
||||
|
||||
private val scriptEngineManager = ScriptEngineManager()
|
||||
|
||||
override val httpClient: OkHttpClient = OkHttpClient.Builder()
|
||||
.cookieJar(cookieJar)
|
||||
.addInterceptor(CloudFlareInterceptor())
|
||||
@@ -37,9 +40,9 @@ class MangaLoaderContextImpl : MangaLoaderContext() {
|
||||
override suspend fun evaluateJs(script: String): String? = evaluateJs("", script)
|
||||
|
||||
override suspend fun evaluateJs(baseUrl: String, script: String): String? = runInterruptible(Dispatchers.Default) {
|
||||
QuackContext.create().use {
|
||||
it.evaluate(script)?.toString()
|
||||
}
|
||||
val nashorn = scriptEngineManager.getEngineByName("nashorn")
|
||||
?: error("JavaScript engine is not available")
|
||||
nashorn.eval(script)?.toString()?.takeUnless { it.isEmpty() || it == "null" }
|
||||
}
|
||||
|
||||
override fun getConfig(source: MangaSource): MangaSourceConfig = DefaultMangaSourceConfig()
|
||||
|
||||
Reference in New Issue
Block a user