mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
739f889949
commit
3bb8c0c3ab
@ -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)
|
||||||
|
|| url.startsWith("https://", true)
|
||||||
|
) {
|
||||||
|
kotlin.runCatching {
|
||||||
val mURL = URL(baseUrl)
|
val mURL = URL(baseUrl)
|
||||||
val host: String = mURL.host
|
val host: String = mURL.host
|
||||||
//判断是否为ip
|
//判断是否为ip
|
||||||
if (isIPAddress(host)) return baseUrl
|
if (isIPAddress(host)) return baseUrl
|
||||||
//PublicSuffixDatabase处理域名
|
//PublicSuffixDatabase处理域名
|
||||||
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
|
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
|
||||||
}.getOrDefault(url)
|
}.getOrDefault(baseUrl)
|
||||||
|
} else {
|
||||||
|
baseUrl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user