vomic: override base URL preference (#17245)
This commit is contained in:
parent
cd259ffb43
commit
4ec625f582
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'vomic'
|
extName = 'vomic'
|
||||||
pkgNameSuffix = 'zh.vomic'
|
pkgNameSuffix = 'zh.vomic'
|
||||||
extClass = '.Vomic'
|
extClass = '.Vomic'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.extension.zh.vomic
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.EditTextPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
|
@ -21,6 +21,7 @@ import okhttp3.Response
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.io.IOException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
|
@ -35,17 +36,21 @@ class Vomic : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
override val supportsLatest = false
|
override val supportsLatest = false
|
||||||
|
|
||||||
override val baseUrl: String
|
override val baseUrl = "http://" + Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000).getString(DOMAIN_PREF, DEFAULT_DOMAIN)
|
||||||
|
|
||||||
private val apiUrl: String
|
private val apiUrl = baseUrl
|
||||||
|
|
||||||
init {
|
override val client = network.client.newBuilder().addInterceptor { chain ->
|
||||||
val mirrors = MIRRORS
|
try {
|
||||||
val mirrorIndex = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
val response = chain.proceed(chain.request())
|
||||||
.getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1)
|
if (response.isSuccessful) {
|
||||||
baseUrl = "http://" + mirrors[mirrorIndex]
|
return@addInterceptor response
|
||||||
apiUrl = "http://" + mirrors[mirrorIndex].replace("www.", "api.")
|
|
||||||
}
|
}
|
||||||
|
response.close()
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
}
|
||||||
|
throw IOException("请在插件设置中修改网址")
|
||||||
|
}.build()
|
||||||
|
|
||||||
override fun headersBuilder() = Headers.Builder().add("User-Agent", System.getProperty("http.agent")!!)
|
override fun headersBuilder() = Headers.Builder().add("User-Agent", System.getProperty("http.agent")!!)
|
||||||
|
|
||||||
|
@ -150,14 +155,11 @@ class Vomic : HttpSource(), ConfigurableSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
ListPreference(screen.context).apply {
|
EditTextPreference(screen.context).apply {
|
||||||
val mirrors = MIRRORS
|
key = DOMAIN_PREF
|
||||||
key = MIRROR_PREF
|
title = "网址"
|
||||||
title = "镜像网址"
|
summary = "不带 http:// 前缀,重启生效\n备选网址:119.23.243.52"
|
||||||
summary = "%s\n重启生效"
|
setDefaultValue(DEFAULT_DOMAIN)
|
||||||
entries = mirrors
|
|
||||||
entryValues = Array(mirrors.size) { it.toString() }
|
|
||||||
setDefaultValue("0")
|
|
||||||
}.let(screen::addPreference)
|
}.let(screen::addPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +169,8 @@ class Vomic : HttpSource(), ConfigurableSource {
|
||||||
json.decodeFromString<ResponseDto<T>>(body.string()).data
|
json.decodeFromString<ResponseDto<T>>(body.string()).data
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val MIRROR_PREF = "MIRROR"
|
private const val DOMAIN_PREF = "DOMAIN"
|
||||||
private val MIRRORS get() = arrayOf("www.vomicmh.com", "www.iewoai.com")
|
private const val DEFAULT_DOMAIN = "www.vomicmh.com"
|
||||||
|
|
||||||
private val dateFormat by lazy { SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH) }
|
private val dateFormat by lazy { SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue