TempleScan(es): Auto update domain (#9651)
* autoupdate domain * use location header * remove ci check
This commit is contained in:
parent
46b898fcd4
commit
09bab2593b
@ -2,8 +2,8 @@ ext {
|
||||
extName = 'Temple Scan'
|
||||
extClass = '.TempleScanEsp'
|
||||
themePkg = 'madara'
|
||||
baseUrl = 'https://templescanesp.caserosvive.com.ar'
|
||||
overrideVersionCode = 3
|
||||
baseUrl = 'https://templescanesp.justep.me'
|
||||
overrideVersionCode = 4
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,16 @@ import android.content.SharedPreferences
|
||||
import android.widget.Toast
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import keiyoushi.utils.getPreferences
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import org.jsoup.nodes.Element
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
@ -18,17 +21,30 @@ import java.util.Locale
|
||||
class TempleScanEsp :
|
||||
Madara(
|
||||
"Temple Scan",
|
||||
"https://templescanesp.caserosvive.com.ar",
|
||||
"https://templescanesp.justep.me",
|
||||
"es",
|
||||
dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")),
|
||||
),
|
||||
ConfigurableSource {
|
||||
|
||||
private val isCi = System.getenv("CI") == "true"
|
||||
override val baseUrl get() = preferences.prefBaseUrl
|
||||
|
||||
override val baseUrl get() = when {
|
||||
isCi -> super.baseUrl
|
||||
else -> preferences.prefBaseUrl
|
||||
private val fetchedDomainUrl: String by lazy {
|
||||
if (!preferences.fetchDomainPref()) return@lazy preferences.prefBaseUrl
|
||||
try {
|
||||
val initClient = network.cloudflareClient.newBuilder()
|
||||
.followRedirects(false)
|
||||
.build()
|
||||
val headers = super.headersBuilder().build()
|
||||
val response = initClient.newCall(GET(preferences.prefBaseUrl, headers)).execute()
|
||||
if (!response.isRedirect) return@lazy preferences.prefBaseUrl
|
||||
val newHost = response.header("Location")?.toHttpUrlOrNull() ?: return@lazy preferences.prefBaseUrl
|
||||
val newDomain = "https://${newHost.host}"
|
||||
preferences.prefBaseUrl = newDomain
|
||||
newDomain
|
||||
} catch (_: Exception) {
|
||||
preferences.prefBaseUrl
|
||||
}
|
||||
}
|
||||
|
||||
override val versionId = 4
|
||||
@ -39,7 +55,7 @@ class TempleScanEsp :
|
||||
|
||||
override val client by lazy {
|
||||
super.client.newBuilder()
|
||||
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1)
|
||||
.rateLimitHost(fetchedDomainUrl.toHttpUrl(), 3, 1)
|
||||
.build()
|
||||
}
|
||||
|
||||
@ -100,8 +116,17 @@ class TempleScanEsp :
|
||||
true
|
||||
}
|
||||
}.also { screen.addPreference(it) }
|
||||
|
||||
SwitchPreferenceCompat(screen.context).apply {
|
||||
key = FETCH_DOMAIN_PREF
|
||||
title = "Buscar dominio automáticamente"
|
||||
summary = "Intenta buscar el dominio automáticamente al abrir la fuente."
|
||||
setDefaultValue(true)
|
||||
}.also { screen.addPreference(it) }
|
||||
}
|
||||
|
||||
private fun SharedPreferences.fetchDomainPref() = getBoolean(FETCH_DOMAIN_PREF, true)
|
||||
|
||||
private var _cachedBaseUrl: String? = null
|
||||
private var SharedPreferences.prefBaseUrl: String
|
||||
get() {
|
||||
@ -118,5 +143,6 @@ class TempleScanEsp :
|
||||
companion object {
|
||||
private const val BASE_URL_PREF = "overrideBaseUrl"
|
||||
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
|
||||
private const val FETCH_DOMAIN_PREF = "fetchDomain"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user