pull/45/head
kunfei 5 years ago
parent 26eff62778
commit ab3244d7a3
  1. 8
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
  2. 15
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  3. 4
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -78,7 +78,7 @@ class AjaxWebView {
} }
fun load(params: AjaxParams) { fun load(params: AjaxParams) {
if (params.audioSuffix != "") { if (params.sourceRegex != "") {
mHandler.obtainMessage(MSG_SNIFF_START, params) mHandler.obtainMessage(MSG_SNIFF_START, params)
.sendToTarget() .sendToTarget()
} else { } else {
@ -97,7 +97,7 @@ class AjaxWebView {
var postData: ByteArray? = null var postData: ByteArray? = null
var headerMap: Map<String, String>? = null var headerMap: Map<String, String>? = null
var cookieStore: CookieStore? = null var cookieStore: CookieStore? = null
var audioSuffix: String? = null var sourceRegex: String? = null
var javaScript: String? = null var javaScript: String? = null
private var audioSuffixList: List<String>? = null private var audioSuffixList: List<String>? = null
@ -105,7 +105,7 @@ class AjaxWebView {
get() = this.headerMap?.get("User-Agent") get() = this.headerMap?.get("User-Agent")
val isSniff: Boolean val isSniff: Boolean
get() = !TextUtils.isEmpty(audioSuffix) get() = !TextUtils.isEmpty(sourceRegex)
fun setCookie(url: String) { fun setCookie(url: String) {
if (cookieStore != null) { if (cookieStore != null) {
@ -125,7 +125,7 @@ class AjaxWebView {
fun getAudioSuffixList(): List<String>? { fun getAudioSuffixList(): List<String>? {
if (audioSuffixList == null) { if (audioSuffixList == null) {
audioSuffixList = if (isSniff) { audioSuffixList = if (isSniff) {
audioSuffix?.split("\\|\\|".toRegex()) sourceRegex?.split("\\|\\|".toRegex())
} else { } else {
Collections.emptyList() Collections.emptyList()
} }

@ -1,11 +1,11 @@
package io.legado.app.help.http package io.legado.app.help.http
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.* import okhttp3.*
import retrofit2.Retrofit import retrofit2.Retrofit
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.coroutines.resume
object HttpHelper { object HttpHelper {
@ -74,23 +74,20 @@ object HttpHelper {
} }
} }
@ExperimentalCoroutinesApi
suspend fun ajax(params: AjaxWebView.AjaxParams): String = suspend fun ajax(params: AjaxWebView.AjaxParams): String =
suspendCancellableCoroutine { block -> suspendCancellableCoroutine { block ->
val webView = AjaxWebView() val webView = AjaxWebView()
block.invokeOnCancellation {
webView.destroyWebView()
}
webView.callback = object : AjaxWebView.Callback() { webView.callback = object : AjaxWebView.Callback() {
override fun onResult(result: String) { override fun onResult(result: String) {
block.resume(result) { block.resume(result)
webView.destroyWebView()
}
} }
override fun onError(error: Throwable) { override fun onError(error: Throwable) {
block.resume(error.localizedMessage) { block.resume(error.localizedMessage)
webView.destroyWebView()
}
} }
} }
webView.load(params) webView.load(params)
} }

@ -59,6 +59,7 @@ class AnalyzeUrl(
private var body: RequestBody? = null private var body: RequestBody? = null
private var method = RequestMethod.GET private var method = RequestMethod.GET
private var webViewJs: String? = null private var webViewJs: String? = null
private var sourceRegex: String? = null
val postData: ByteArray val postData: ByteArray
get() { get() {
@ -182,6 +183,7 @@ class AnalyzeUrl(
options["body"]?.let { bodyTxt = it } options["body"]?.let { bodyTxt = it }
options["charset"]?.let { charset = it } options["charset"]?.let { charset = it }
options["js"]?.let { webViewJs = it } options["js"]?.let { webViewJs = it }
options["sourceRegex"]?.let { sourceRegex = it }
} }
} }
when (method) { when (method) {
@ -302,6 +304,8 @@ class AnalyzeUrl(
val params = AjaxWebView.AjaxParams(tag) val params = AjaxWebView.AjaxParams(tag)
params.url = url params.url = url
params.requestMethod = method params.requestMethod = method
params.javaScript = webViewJs
params.sourceRegex = sourceRegex
return HttpHelper.ajax(params) return HttpHelper.ajax(params)
} }
} }

Loading…
Cancel
Save