135 lines
5.1 KiB
Kotlin
135 lines
5.1 KiB
Kotlin
package com.yingmao.clash.base
|
|
|
|
|
|
import android.text.TextUtils
|
|
import com.cncat.vpn.common.log.Log
|
|
import com.yingmao.clash.net.http.HttpApi
|
|
import com.yingmao.clash.net.http.NetService
|
|
import com.orhanobut.logger.Logger
|
|
import com.tencent.mmkv.MMKV
|
|
import com.yingmao.clash.BuildConfig
|
|
import com.yingmao.clash.conf.BZYConstants
|
|
import com.yingmao.clash.entity.DomainRsp
|
|
import com.yingmao.clash.listener.AsyncBodyCallback
|
|
import com.yingmao.clash.listener.AsyncCallback
|
|
import com.yingmao.clash.net.http.HttpReqType
|
|
import com.yingmao.clash.util.AESUtil
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.launch
|
|
import java.util.ArrayList
|
|
|
|
open class PublicViewMode : BaseViewMode() {
|
|
fun getHost(callback: AsyncCallback) {
|
|
val rt =
|
|
NetService.instances.createFreeBaseUrl("https://pubtofile.oss-cn-hongkong.aliyuncs.com/")
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try {
|
|
val host =rt.getHost()
|
|
host.takeIf { it.isNotEmpty() }?.let {
|
|
val decryptedHost = AESUtil.decrypt(it)
|
|
val hostList = decryptedHost.split("+")
|
|
if (hostList.isNotEmpty()) {
|
|
//第一个为推荐域名
|
|
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_FIRST_HOST, hostList[0])
|
|
MMKV.defaultMMKV()
|
|
.encode(BZYConstants.MMKV_KEY_ROUTER_HOST, hostList.toSet())
|
|
}
|
|
}
|
|
|
|
callback.suc()
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
|
|
fun getHostByGithub(callback: AsyncCallback) {
|
|
val rt = NetService.instances.createFreeBaseUrl("https://raw.githubusercontent.com/")
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try {
|
|
val host = rt.getHostGithubjl()
|
|
host.takeIf { it.isNotEmpty() }?.let {
|
|
val decryptedHost = AESUtil.decrypt(it)
|
|
val hostList = decryptedHost.split("+")
|
|
if (hostList.isNotEmpty()) {
|
|
//第一个为推荐域名
|
|
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_FIRST_HOST, hostList[0])
|
|
|
|
MMKV.defaultMMKV()
|
|
.encode(BZYConstants.MMKV_KEY_ROUTER_HOST, hostList.toSet())
|
|
}
|
|
}
|
|
callback.suc()
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
|
|
fun getHostByAWS(callback: AsyncCallback) {
|
|
val rt =
|
|
NetService.instances.createFreeBaseUrl("https://wfjsq.s3.ap-east-1.amazonaws.com/")
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try {
|
|
val host =rt.getHostAWS()
|
|
host.takeIf { it.isNotEmpty() }?.let {
|
|
val decryptedHost = AESUtil.decrypt(it)
|
|
val hostList = decryptedHost.split("+")
|
|
if (hostList.isNotEmpty()) {
|
|
//第一个为推荐域名
|
|
MMKV.defaultMMKV().encode(BZYConstants.MMKV_KEY_FIRST_HOST, hostList[0])
|
|
MMKV.defaultMMKV()
|
|
.encode(BZYConstants.MMKV_KEY_ROUTER_HOST, hostList.toSet())
|
|
}
|
|
}
|
|
callback.suc()
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
fun getLocalHost(callback: AsyncBodyCallback) {
|
|
val baseUrl=BuildConfig.service_url
|
|
val rt = NetService.instances.createFreeBaseUrl(baseUrl)
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try { //TODO bug 会引起崩溃
|
|
var host = rt.getLocalKefuHost()
|
|
callback.suc(host)
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
fun getCustomServiceNet(callback: AsyncBodyCallback) {
|
|
val rt =
|
|
NetService.instances.createFreeBaseUrl("https://pubtofilegz.oss-rg-china-mainland.aliyuncs.com/")
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try {
|
|
val host = rt.getKklNetHost()
|
|
android.util.Log.i("getCustomServiceHost","Kf host::"+host)
|
|
callback.suc(host)
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
fun getCustomServiceNetS3(callback: AsyncBodyCallback) {
|
|
val rt =
|
|
NetService.instances.createFreeBaseUrl("https://wfjsq.s3.ap-east-1.amazonaws.com/")
|
|
doAsyncNoNeedReturn(HttpReqType.GET_HOST) {
|
|
try {
|
|
val host = rt.getKklNetS3()
|
|
android.util.Log.i("getCustomServiceHost","Kf host::"+host)
|
|
callback.suc(host)
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
callback.err()
|
|
}
|
|
}
|
|
}
|
|
} |