优化dataUri处理

pull/1713/head
kunfei 3 years ago
parent a957714de5
commit 9c02293c26
  1. 4
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  2. 4
      app/src/main/java/io/legado/app/model/webBook/BookList.kt
  3. 2
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -127,9 +127,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接") Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
try { try {
analyzeRule.getString(infoRule.coverUrl).let { analyzeRule.getString(infoRule.coverUrl).let {
if (it.startsWith("data:")) { if (it.isNotEmpty()) {
book.coverUrl = it
} else if (it.isNotEmpty()) {
book.coverUrl = book.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it) NetworkUtils.getAbsoluteURL(baseUrl, it)
} }

@ -229,9 +229,7 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log) Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
try { try {
analyzeRule.getString(ruleCoverUrl).let { analyzeRule.getString(ruleCoverUrl).let {
if (it.startsWith("data:")) { if (it.isNotEmpty()) {
searchBook.coverUrl = it
} else if (it.isNotEmpty()) {
searchBook.coverUrl = searchBook.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it) NetworkUtils.getAbsoluteURL(baseUrl, it)
} }

@ -4,6 +4,7 @@ import android.net.ConnectivityManager
import android.net.NetworkCapabilities import android.net.NetworkCapabilities
import android.os.Build import android.os.Build
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.constant.AppPattern
import okhttp3.internal.publicsuffix.PublicSuffixDatabase import okhttp3.internal.publicsuffix.PublicSuffixDatabase
import splitties.systemservices.connectivityManager import splitties.systemservices.connectivityManager
@ -110,6 +111,7 @@ object NetworkUtils {
fun getAbsoluteURL(baseURL: String?, relativePath: String): String { fun getAbsoluteURL(baseURL: String?, relativePath: String): String {
if (baseURL.isNullOrEmpty()) return relativePath if (baseURL.isNullOrEmpty()) return relativePath
if (relativePath.isAbsUrl()) return relativePath if (relativePath.isAbsUrl()) return relativePath
if (relativePath.matches(AppPattern.dataUriRegex)) return relativePath
if (relativePath.startsWith("javascript")) return "" if (relativePath.startsWith("javascript")) return ""
var relativeUrl = relativePath var relativeUrl = relativePath
try { try {

Loading…
Cancel
Save