From 10e110676068951ccac15c74b0ebefc039dffe95 Mon Sep 17 00:00:00 2001 From: DitFranXX <45893338+DitFranXX@users.noreply.github.com> Date: Fri, 15 Mar 2019 01:45:21 +0900 Subject: [PATCH] [Cloudflare] Fix SyntaxError due to recent js challenge changes. (#1876) From Anorov/cloudflare-scrape#193 Related issues: inorichi/tachiyomi-extensions#894 --- .../tachiyomi/network/CloudflareInterceptor.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt index 18a87170be..0824e9b6d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -1,11 +1,7 @@ package eu.kanade.tachiyomi.network import com.squareup.duktape.Duktape -import okhttp3.CacheControl -import okhttp3.HttpUrl -import okhttp3.Interceptor -import okhttp3.Request -import okhttp3.Response +import okhttp3.* class CloudflareInterceptor : Interceptor { @@ -48,18 +44,18 @@ class CloudflareInterceptor : Interceptor { } val js = operation - .replace(Regex("""a\.value = (.+ \+ t\.length).+"""), "$1") + .replace(Regex("""a\.value = (.+ \+ t\.length(\).toFixed\(10\))?).+"""), "$1") .replace(Regex("""\s{3,}[a-z](?: = |\.).+"""), "") .replace("t.length", "${domain.length}") .replace("\n", "") - val result = duktape.evaluate(js) as Double + val result = duktape.evaluate(js) as String val cloudflareUrl = HttpUrl.parse("${url.scheme()}://$domain/cdn-cgi/l/chk_jschl")!! .newBuilder() .addQueryParameter("jschl_vc", challenge) .addQueryParameter("pass", pass) - .addQueryParameter("jschl_answer", "$result") + .addQueryParameter("jschl_answer", result) .toString() val cloudflareHeaders = originalRequest.headers()