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

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

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

Loading…
Cancel
Save