|
|
@ -141,10 +141,15 @@ object NetworkUtils { |
|
|
|
|
|
|
|
|
|
|
|
fun getBaseUrl(url: String?): String? { |
|
|
|
fun getBaseUrl(url: String?): String? { |
|
|
|
url ?: return null |
|
|
|
url ?: return null |
|
|
|
val index = url.indexOf("/", 9) |
|
|
|
if (url.startsWith("http://", true) |
|
|
|
return if (index == -1) { |
|
|
|
|| url.startsWith("https://", true) |
|
|
|
url |
|
|
|
) { |
|
|
|
} else url.substring(0, index) |
|
|
|
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 { |
|
|
|
fun getSubDomain(url: String): String { |
|
|
|
val baseUrl = getBaseUrl(url) ?: return url |
|
|
|
val baseUrl = getBaseUrl(url) ?: return url |
|
|
|
return if (url.startsWith("http://", true) |
|
|
|
return kotlin.runCatching { |
|
|
|
|| url.startsWith("https://", true) |
|
|
|
val mURL = URL(baseUrl) |
|
|
|
) { |
|
|
|
val host: String = mURL.host |
|
|
|
kotlin.runCatching { |
|
|
|
//判断是否为ip |
|
|
|
val mURL = URL(baseUrl) |
|
|
|
if (isIPAddress(host)) return baseUrl |
|
|
|
val host: String = mURL.host |
|
|
|
//PublicSuffixDatabase处理域名 |
|
|
|
//判断是否为ip |
|
|
|
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl |
|
|
|
if (isIPAddress(host)) return baseUrl |
|
|
|
}.getOrDefault(baseUrl) |
|
|
|
//PublicSuffixDatabase处理域名 |
|
|
|
|
|
|
|
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl |
|
|
|
|
|
|
|
}.getOrDefault(baseUrl) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
baseUrl |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|