mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
perf(AnalyzeUrl):skip init block when mUrl is DataURL
This commit is contained in:
@@ -6,8 +6,8 @@ import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.bumptech.glide.RequestBuilder
|
||||
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||
import io.legado.app.utils.isAbsUrl
|
||||
import io.legado.app.utils.isDataUrl
|
||||
import io.legado.app.utils.isContentScheme
|
||||
import java.io.File
|
||||
|
||||
@@ -20,7 +20,7 @@ object ImageLoader {
|
||||
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
|
||||
return when {
|
||||
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
|
||||
dataUriRegex.find(path) != null -> GlideApp.with(context).load(path)
|
||||
path.isDataUrl() -> GlideApp.with(context).load(path)
|
||||
path.isAbsUrl() -> GlideApp.with(context).load(path)
|
||||
path.isContentScheme() -> GlideApp.with(context).load(Uri.parse(path))
|
||||
else -> kotlin.runCatching {
|
||||
@@ -34,6 +34,7 @@ object ImageLoader {
|
||||
fun loadBitmap(context: Context, path: String?): RequestBuilder<Bitmap> {
|
||||
return when {
|
||||
path.isNullOrEmpty() -> GlideApp.with(context).asBitmap().load(path)
|
||||
path.isDataUrl() -> GlideApp.with(context).asBitmap().load(path)
|
||||
path.isAbsUrl() -> GlideApp.with(context).asBitmap().load(path)
|
||||
path.isContentScheme() -> GlideApp.with(context).asBitmap().load(Uri.parse(path))
|
||||
else -> kotlin.runCatching {
|
||||
|
||||
@@ -71,16 +71,18 @@ class AnalyzeUrl(
|
||||
private var webJs: String? = null
|
||||
|
||||
init {
|
||||
val urlMatcher = paramPattern.matcher(baseUrl)
|
||||
if (urlMatcher.find()) baseUrl = baseUrl.substring(0, urlMatcher.start())
|
||||
(headerMapF ?: source?.getHeaderMap(true))?.let {
|
||||
headerMap.putAll(it)
|
||||
if (it.containsKey("proxy")) {
|
||||
proxy = it["proxy"]
|
||||
headerMap.remove("proxy")
|
||||
if (!mUrl.isDataUrl()) {
|
||||
val urlMatcher = paramPattern.matcher(baseUrl)
|
||||
if (urlMatcher.find()) baseUrl = baseUrl.substring(0, urlMatcher.start())
|
||||
(headerMapF ?: source?.getHeaderMap(true))?.let {
|
||||
headerMap.putAll(it)
|
||||
if (it.containsKey("proxy")) {
|
||||
proxy = it["proxy"]
|
||||
headerMap.remove("proxy")
|
||||
}
|
||||
}
|
||||
initUrl()
|
||||
}
|
||||
initUrl()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -457,10 +459,9 @@ class AnalyzeUrl(
|
||||
* 访问网站,返回ByteArray
|
||||
*/
|
||||
suspend fun getByteArrayAwait(): ByteArray {
|
||||
val concurrentRecord = fetchStart()
|
||||
@Suppress("RegExpRedundantEscape")
|
||||
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
||||
val concurrentRecord = fetchStart()
|
||||
setCookie(source?.getKey())
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
if (dataUriFindResult != null) {
|
||||
val dataUriBase64 = dataUriFindResult.groupValues[1]
|
||||
@@ -468,6 +469,7 @@ class AnalyzeUrl(
|
||||
fetchEnd(concurrentRecord)
|
||||
return byteArray
|
||||
} else {
|
||||
setCookie(source?.getKey())
|
||||
val byteArray = getProxyClient(proxy).newCallResponseBody(retry) {
|
||||
addHeaders(headerMap)
|
||||
when (method) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package io.legado.app.utils
|
||||
|
||||
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||
import android.icu.text.Collator
|
||||
import android.icu.util.ULocale
|
||||
import android.net.Uri
|
||||
@@ -25,6 +26,11 @@ fun String?.isAbsUrl() =
|
||||
it.startsWith("http://", true) || it.startsWith("https://", true)
|
||||
} ?: false
|
||||
|
||||
fun String?.isDataUrl() =
|
||||
this?.let {
|
||||
dataUriRegex.matches(it)
|
||||
} ?: false
|
||||
|
||||
fun String?.isJson(): Boolean =
|
||||
this?.run {
|
||||
val str = this.trim()
|
||||
|
||||
Reference in New Issue
Block a user