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

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

Loading…
Cancel
Save