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