xfani: add preference to ignore ssl verify issue.
This commit is contained in:
parent
0b13e55d99
commit
c4127cfbdd
1 changed files with 45 additions and 15 deletions
|
@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.animeextension.zh.xfani
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||||
|
@ -20,6 +22,7 @@ import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.Interceptor
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
@ -30,6 +33,7 @@ import uy.kohesive.injekt.injectLazy
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.security.cert.X509Certificate
|
import java.security.cert.X509Certificate
|
||||||
import javax.net.ssl.SSLContext
|
import javax.net.ssl.SSLContext
|
||||||
|
import javax.net.ssl.SSLHandshakeException
|
||||||
import javax.net.ssl.TrustManager
|
import javax.net.ssl.TrustManager
|
||||||
import javax.net.ssl.X509TrustManager
|
import javax.net.ssl.X509TrustManager
|
||||||
|
|
||||||
|
@ -71,11 +75,23 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
override val client: OkHttpClient
|
override val client: OkHttpClient
|
||||||
get() = network.client.newBuilder().ignoreAllSSLErrors().build()
|
get() = if (preferences.getBoolean(PREF_KEY_IGNORE_SSL_ERROR, false)) {
|
||||||
|
network.client.newBuilder().ignoreAllSSLErrors().build()
|
||||||
|
} else {
|
||||||
|
network.client.newBuilder().addInterceptor(::checkSSLErrorInterceptor).build()
|
||||||
|
}
|
||||||
|
|
||||||
private val selectedVideoSource
|
private val selectedVideoSource
|
||||||
get() = preferences.getString(PREF_KEY_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE)!!.toInt()
|
get() = preferences.getString(PREF_KEY_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE)!!.toInt()
|
||||||
|
|
||||||
|
private fun checkSSLErrorInterceptor(chain: Interceptor.Chain): Response {
|
||||||
|
try {
|
||||||
|
return chain.proceed(chain.request())
|
||||||
|
} catch (e: SSLHandshakeException) {
|
||||||
|
throw SSLHandshakeException("SSL证书验证异常,可以尝试在设置中忽略SSL验证问题。")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun animeDetailsParse(response: Response): SAnime {
|
override fun animeDetailsParse(response: Response): SAnime {
|
||||||
val jsoup = response.asJsoup()
|
val jsoup = response.asJsoup()
|
||||||
return SAnime.create().apply {
|
return SAnime.create().apply {
|
||||||
|
@ -221,7 +237,8 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
screen.addPreference(
|
screen.apply {
|
||||||
|
addPreference(
|
||||||
ListPreference(screen.context).apply {
|
ListPreference(screen.context).apply {
|
||||||
key = PREF_KEY_VIDEO_SOURCE
|
key = PREF_KEY_VIDEO_SOURCE
|
||||||
title = "请设置首选视频源线路"
|
title = "请设置首选视频源线路"
|
||||||
|
@ -235,10 +252,23 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
addPreference(
|
||||||
|
SwitchPreferenceCompat(screen.context).apply {
|
||||||
|
key = PREF_KEY_IGNORE_SSL_ERROR
|
||||||
|
title = "忽略SSL证书校验"
|
||||||
|
setDefaultValue(false)
|
||||||
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
|
Toast.makeText(screen.context, "重启应用后生效", Toast.LENGTH_SHORT).show()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PREF_KEY_VIDEO_SOURCE = "PREF_KEY_VIDEO_SOURCE"
|
const val PREF_KEY_VIDEO_SOURCE = "PREF_KEY_VIDEO_SOURCE"
|
||||||
|
const val PREF_KEY_IGNORE_SSL_ERROR = "PREF_KEY_IGNORE_SSL_ERROR"
|
||||||
|
|
||||||
const val DEFAULT_VIDEO_SOURCE = "0"
|
const val DEFAULT_VIDEO_SOURCE = "0"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue