优化
This commit is contained in:
@@ -4,7 +4,8 @@ import android.annotation.SuppressLint
|
|||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
import cn.hutool.core.net.URLEncodeUtil
|
import cn.hutool.core.codec.PercentCodec
|
||||||
|
import cn.hutool.core.net.RFC3986
|
||||||
import cn.hutool.core.util.HexUtil
|
import cn.hutool.core.util.HexUtil
|
||||||
import com.bumptech.glide.load.model.GlideUrl
|
import com.bumptech.glide.load.model.GlideUrl
|
||||||
import com.script.buildScriptBindings
|
import com.script.buildScriptBindings
|
||||||
@@ -90,6 +91,8 @@ class AnalyzeUrl(
|
|||||||
companion object {
|
companion object {
|
||||||
val paramPattern: Pattern = Pattern.compile("\\s*,\\s*(?=\\{)")
|
val paramPattern: Pattern = Pattern.compile("\\s*,\\s*(?=\\{)")
|
||||||
private val pagePattern = Pattern.compile("<(.*?)>")
|
private val pagePattern = Pattern.compile("<(.*?)>")
|
||||||
|
private val queryEncoder =
|
||||||
|
RFC3986.UNRESERVED.orNew(PercentCodec.of("!$%&()*+,/:;=?@[\\]^`{|}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var ruleUrl = ""
|
var ruleUrl = ""
|
||||||
@@ -286,6 +289,12 @@ class AnalyzeUrl(
|
|||||||
charset == "escape" -> null
|
charset == "escape" -> null
|
||||||
else -> charset(charset)
|
else -> charset(charset)
|
||||||
}
|
}
|
||||||
|
if (isQuery && charset != null) {
|
||||||
|
if (NetworkUtils.encodedQuery(params)) {
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
return queryEncoder.encode(params, charset)
|
||||||
|
}
|
||||||
val len = params.length
|
val len = params.length
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
var pos = 0
|
var pos = 0
|
||||||
@@ -307,10 +316,10 @@ class AnalyzeUrl(
|
|||||||
key = params.substring(pos, eqOffset)
|
key = params.substring(pos, eqOffset)
|
||||||
value = params.substring(eqOffset + 1, ampOffset)
|
value = params.substring(eqOffset + 1, ampOffset)
|
||||||
}
|
}
|
||||||
sb.appendEncoded(key, isQuery, checkEncoded, charset)
|
sb.appendEncoded(key, checkEncoded, charset)
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
sb.append("=")
|
sb.append("=")
|
||||||
sb.appendEncoded(value, isQuery, checkEncoded, charset)
|
sb.appendEncoded(value, checkEncoded, charset)
|
||||||
}
|
}
|
||||||
pos = ampOffset + 1
|
pos = ampOffset + 1
|
||||||
}
|
}
|
||||||
@@ -319,19 +328,13 @@ class AnalyzeUrl(
|
|||||||
|
|
||||||
private fun StringBuilder.appendEncoded(
|
private fun StringBuilder.appendEncoded(
|
||||||
value: String,
|
value: String,
|
||||||
isQuery: Boolean,
|
|
||||||
checkEncoded: Boolean,
|
checkEncoded: Boolean,
|
||||||
charset: Charset?
|
charset: Charset?
|
||||||
) {
|
) {
|
||||||
if (checkEncoded &&
|
if (checkEncoded && NetworkUtils.encodedForm(value)) {
|
||||||
!((isQuery && !NetworkUtils.encodedQuery(value)) ||
|
|
||||||
(!isQuery && !NetworkUtils.encodedForm(value)))
|
|
||||||
) {
|
|
||||||
append(value)
|
append(value)
|
||||||
} else if (charset == null) {
|
} else if (charset == null) {
|
||||||
append(EncoderUtils.escape(value))
|
append(EncoderUtils.escape(value))
|
||||||
} else if (isQuery) {
|
|
||||||
append(URLEncodeUtil.encodeQuery(value, charset))
|
|
||||||
} else {
|
} else {
|
||||||
append(URLEncoder.encode(value, charset))
|
append(URLEncoder.encode(value, charset))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,8 +247,8 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
|||||||
index + 1 to value.bookSourceName
|
index + 1 to value.bookSourceName
|
||||||
}
|
}
|
||||||
}.onCompletion {
|
}.onCompletion {
|
||||||
searchStateData.postValue(false)
|
|
||||||
ensureActive()
|
ensureActive()
|
||||||
|
searchStateData.postValue(false)
|
||||||
searchFinishCallback?.invoke(searchBooks.isEmpty())
|
searchFinishCallback?.invoke(searchBooks.isEmpty())
|
||||||
}.catch {
|
}.catch {
|
||||||
AppLog.put("换源搜索出错\n${it.localizedMessage}", it)
|
AppLog.put("换源搜索出错\n${it.localizedMessage}", it)
|
||||||
|
|||||||
Reference in New Issue
Block a user