pull/1517/head
gedoor 3 years ago
parent 739f889949
commit 3bb8c0c3ab
  1. 24
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -140,7 +140,7 @@ object NetworkUtils {
} }
fun getBaseUrl(url: String?): String? { fun getBaseUrl(url: String?): String? {
if (url == null || !url.startsWith("http")) return null url ?: return null
val index = url.indexOf("/", 9) val index = url.indexOf("/", 9)
return if (index == -1) { return if (index == -1) {
url url
@ -156,14 +156,20 @@ object NetworkUtils {
*/ */
fun getSubDomain(url: String): String { fun getSubDomain(url: String): String {
val baseUrl = getBaseUrl(url) ?: return url val baseUrl = getBaseUrl(url) ?: return url
return kotlin.runCatching { return if (url.startsWith("http://", true)
val mURL = URL(baseUrl) || url.startsWith("https://", true)
val host: String = mURL.host ) {
//判断是否为ip kotlin.runCatching {
if (isIPAddress(host)) return baseUrl val mURL = URL(baseUrl)
//PublicSuffixDatabase处理域名 val host: String = mURL.host
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl //判断是否为ip
}.getOrDefault(url) if (isIPAddress(host)) return baseUrl
//PublicSuffixDatabase处理域名
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
}.getOrDefault(baseUrl)
} else {
baseUrl
}
} }
/** /**

Loading…
Cancel
Save