|
|
@ -155,16 +155,18 @@ object NetworkUtils { |
|
|
|
* http://www.biquge.com.cn => http://biquge.com.cn |
|
|
|
* http://www.biquge.com.cn => http://biquge.com.cn |
|
|
|
* http://www.content.example.com => http://example.com |
|
|
|
* http://www.content.example.com => http://example.com |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun getSubDomain(url: String?): String { |
|
|
|
fun getSubDomain(url: String): String { |
|
|
|
val baseUrl = getBaseUrl(url) ?: return "" |
|
|
|
return kotlin.runCatching { |
|
|
|
val mURL = URL(baseUrl) |
|
|
|
val baseUrl = getBaseUrl(url) ?: return "" |
|
|
|
val schema: String = mURL.protocol |
|
|
|
val mURL = URL(baseUrl) |
|
|
|
val host: String = mURL.host |
|
|
|
val schema: String = mURL.protocol |
|
|
|
//判断是否为ip |
|
|
|
val host: String = mURL.host |
|
|
|
if (isIPAddress(host)) return baseUrl |
|
|
|
//判断是否为ip |
|
|
|
//PublicSuffixDatabase处理域名 |
|
|
|
if (isIPAddress(host)) return baseUrl |
|
|
|
val domain = PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) |
|
|
|
//PublicSuffixDatabase处理域名 |
|
|
|
return if (domain == null) baseUrl else "${schema}://${domain}" |
|
|
|
val domain = PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) |
|
|
|
|
|
|
|
if (domain == null) baseUrl else "${schema}://${domain}" |
|
|
|
|
|
|
|
}.getOrDefault(url) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|