mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
3bb8c0c3ab
commit
4fd13433ed
@ -141,10 +141,15 @@ object NetworkUtils {
|
||||
|
||||
fun getBaseUrl(url: String?): String? {
|
||||
url ?: return null
|
||||
val index = url.indexOf("/", 9)
|
||||
return if (index == -1) {
|
||||
url
|
||||
} else url.substring(0, index)
|
||||
if (url.startsWith("http://", true)
|
||||
|| url.startsWith("https://", true)
|
||||
) {
|
||||
val index = url.indexOf("/", 9)
|
||||
return if (index == -1) {
|
||||
url
|
||||
} else url.substring(0, index)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,20 +161,14 @@ object NetworkUtils {
|
||||
*/
|
||||
fun getSubDomain(url: String): String {
|
||||
val baseUrl = getBaseUrl(url) ?: return url
|
||||
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(baseUrl)
|
||||
} else {
|
||||
baseUrl
|
||||
}
|
||||
return kotlin.runCatching {
|
||||
val mURL = URL(baseUrl)
|
||||
val host: String = mURL.host
|
||||
//判断是否为ip
|
||||
if (isIPAddress(host)) return baseUrl
|
||||
//PublicSuffixDatabase处理域名
|
||||
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
|
||||
}.getOrDefault(baseUrl)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user