mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-02 10:24:35 -05:00
Remove Playwright (#643)
This commit is contained in:
@@ -1,24 +1,11 @@
|
||||
package eu.kanade.tachiyomi.network.interceptor
|
||||
|
||||
import com.microsoft.playwright.Browser
|
||||
import com.microsoft.playwright.BrowserType.LaunchOptions
|
||||
import com.microsoft.playwright.Page
|
||||
import com.microsoft.playwright.Playwright
|
||||
import com.microsoft.playwright.PlaywrightException
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.interceptor.CFClearance.resolveWithWebView
|
||||
import mu.KotlinLogging
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import suwayomi.tachidesk.server.ServerConfig
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.IOException
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import kotlin.time.DurationUnit
|
||||
|
||||
class CloudflareInterceptor : Interceptor {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
@@ -38,7 +25,7 @@ class CloudflareInterceptor : Interceptor {
|
||||
return originalResponse
|
||||
}
|
||||
|
||||
throw IOException("playwrite is diabled for v0.6.7")
|
||||
throw IOException("Cloudflare bypass currently disabled ")
|
||||
|
||||
logger.debug { "Cloudflare anti-bot is on, CloudflareInterceptor is kicking in..." }
|
||||
|
||||
@@ -46,7 +33,7 @@ class CloudflareInterceptor : Interceptor {
|
||||
originalResponse.close()
|
||||
network.cookieStore.remove(originalRequest.url.toUri())
|
||||
|
||||
val request = resolveWithWebView(originalRequest)
|
||||
val request = originalRequest // resolveWithWebView(originalRequest)
|
||||
|
||||
chain.proceed(request)
|
||||
} catch (e: Exception) {
|
||||
@@ -71,7 +58,7 @@ object CFClearance {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
|
||||
init {
|
||||
/*init {
|
||||
// Fix the default DriverJar issue by providing our own implementation
|
||||
// ref: https://github.com/microsoft/playwright-java/issues/1138
|
||||
System.setProperty("playwright.driver.impl", "suwayomi.tachidesk.server.util.DriverJar")
|
||||
@@ -140,11 +127,12 @@ object CFClearance {
|
||||
return originalRequest.newBuilder()
|
||||
.header("Cookie", newCookies.joinToString("; ") { "${it.name}=${it.value}" })
|
||||
.build()
|
||||
}
|
||||
}*/
|
||||
|
||||
@Suppress("UNREACHABLE_CODE")
|
||||
fun getWebViewUserAgent(): String {
|
||||
return try {
|
||||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
|
||||
/*return try {
|
||||
throw PlaywrightException("playwrite is diabled for v0.6.7")
|
||||
|
||||
Playwright.create().use { playwright ->
|
||||
@@ -162,10 +150,10 @@ object CFClearance {
|
||||
} catch (e: PlaywrightException) {
|
||||
// Playwright might fail on headless environments like docker
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun getCookies(
|
||||
/*private fun getCookies(
|
||||
page: Page,
|
||||
url: String,
|
||||
): List<Cookie> {
|
||||
@@ -235,7 +223,7 @@ object CFClearance {
|
||||
if (success) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}*/
|
||||
|
||||
private class CloudflareBypassException : Exception()
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package suwayomi.tachidesk.server.util
|
||||
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import net.harawata.appdirs.AppDirsFactory
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.notExists
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
object Chromium {
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@JvmStatic
|
||||
fun preinstall(platformDir: String) {
|
||||
val loader = Thread.currentThread().contextClassLoader
|
||||
val resource = loader.getResource("driver/$platformDir/package/browsers.json") ?: return
|
||||
val json =
|
||||
resource.openStream().use {
|
||||
Json.decodeFromStream<JsonObject>(it)
|
||||
}
|
||||
val revision =
|
||||
json["browsers"]?.jsonArray
|
||||
?.find { it.jsonObject["name"]?.jsonPrimitive?.contentOrNull == "chromium" }
|
||||
?.jsonObject
|
||||
?.get("revision")
|
||||
?.jsonPrimitive
|
||||
?.contentOrNull
|
||||
?: return
|
||||
|
||||
val playwrightDir = AppDirsFactory.getInstance().getUserDataDir("ms-playwright", null, null)
|
||||
val chromiumZip = Path(".").resolve("bin/chromium.zip")
|
||||
val chromePath = Path(playwrightDir).resolve("chromium-$revision")
|
||||
if (chromePath.exists() || chromiumZip.notExists()) return
|
||||
chromePath.createDirectories()
|
||||
|
||||
FileSystems.newFileSystem(chromiumZip, null as ClassLoader?).use {
|
||||
val src = it.getPath("/")
|
||||
Files.walk(src)
|
||||
.asSequence()
|
||||
.forEach { source ->
|
||||
Files.copy(
|
||||
source,
|
||||
chromePath.resolve(source.absolutePathString().removePrefix("/")),
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user