mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 04:28:55 +01:00
Add MangaDex login
This commit is contained in:
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.network
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import exh.log.maybeInjectEHLogger
|
||||
import exh.patch.attachMangaDexLogin
|
||||
import okhttp3.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@@ -14,23 +15,24 @@ import java.security.KeyStore
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import javax.net.ssl.*
|
||||
|
||||
class NetworkHelper(context: Context) {
|
||||
open class NetworkHelper(context: Context) {
|
||||
|
||||
private val cacheDir = File(context.cacheDir, "network_cache")
|
||||
|
||||
private val cacheSize = 5L * 1024 * 1024 // 5 MiB
|
||||
|
||||
val cookieManager = AndroidCookieJar(context)
|
||||
open val cookieManager = AndroidCookieJar(context)
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
open val client = OkHttpClient.Builder()
|
||||
.cookieJar(cookieManager)
|
||||
.cache(Cache(cacheDir, cacheSize))
|
||||
.enableTLS12()
|
||||
.maybeInjectEHLogger()
|
||||
.build()
|
||||
|
||||
val cloudflareClient = client.newBuilder()
|
||||
open val cloudflareClient = client.newBuilder()
|
||||
.addInterceptor(CloudflareInterceptor(context))
|
||||
.attachMangaDexLogin()
|
||||
.build()
|
||||
|
||||
private fun OkHttpClient.Builder.enableTLS12(): OkHttpClient.Builder {
|
||||
|
||||
@@ -24,7 +24,6 @@ import exh.metadata.metadata.PervEdenLang
|
||||
import exh.source.BlacklistedSources
|
||||
import exh.source.DelegatedHttpSource
|
||||
import exh.source.EnhancedHttpSource
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package eu.kanade.tachiyomi.source.online
|
||||
|
||||
import android.app.Application
|
||||
import com.elvishew.xlog.XLog
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.network.newCallWithProgress
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.network.*
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.model.*
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import exh.ui.captcha.SolveCaptchaActivity
|
||||
import exh.source.DelegatedHttpSource
|
||||
import exh.ui.captcha.BrowserActionActivity
|
||||
import exh.util.interceptAsHtml
|
||||
import okhttp3.*
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@@ -28,7 +27,19 @@ abstract class HttpSource : CatalogueSource {
|
||||
/**
|
||||
* Network service.
|
||||
*/
|
||||
protected val network: NetworkHelper by injectLazy()
|
||||
protected val network: NetworkHelper by lazy {
|
||||
val original = Injekt.get<NetworkHelper>()
|
||||
object : NetworkHelper(Injekt.get<Application>()) {
|
||||
override val client: OkHttpClient?
|
||||
get() = delegate?.networkHttpClient ?: original.client
|
||||
|
||||
override val cloudflareClient: OkHttpClient?
|
||||
get() = delegate?.networkCloudflareClient ?: original.cloudflareClient
|
||||
|
||||
override val cookieManager: AndroidCookieJar
|
||||
get() = original.cookieManager
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Preferences that a source may need.
|
||||
@@ -68,36 +79,21 @@ abstract class HttpSource : CatalogueSource {
|
||||
* Default network client for doing requests.
|
||||
*/
|
||||
open val client: OkHttpClient
|
||||
get() = network.client.newBuilder().addInterceptor { chain ->
|
||||
get() = delegate?.baseHttpClient ?: network.client.newBuilder().addInterceptor { chain ->
|
||||
// Automatic captcha detection
|
||||
val response = chain.proceed(chain.request())
|
||||
val body = response.body()
|
||||
if(!response.isSuccessful && body != null) {
|
||||
if(body.contentType()?.type() == "text"
|
||||
&& body.contentType()?.subtype() == "html") {
|
||||
val bodyString = body.string()
|
||||
val rebuiltResponse = response.newBuilder()
|
||||
.body(ResponseBody.create(body.contentType(), bodyString))
|
||||
.build()
|
||||
try {
|
||||
// Search for captcha
|
||||
val parsed = response.asJsoup(html = bodyString)
|
||||
if(parsed.getElementsByClass("g-recaptcha").isNotEmpty()) {
|
||||
// Found it, allow the user to solve this thing
|
||||
SolveCaptchaActivity.launchUniversal(
|
||||
Injekt.get<Application>(),
|
||||
this,
|
||||
chain.request().url().toString()
|
||||
)
|
||||
}
|
||||
} catch(t: Throwable) {
|
||||
// Ignore all errors
|
||||
XLog.w("Captcha detection error!", t)
|
||||
if(!response.isSuccessful) {
|
||||
response.interceptAsHtml { doc ->
|
||||
if (doc.getElementsByClass("g-recaptcha").isNotEmpty()) {
|
||||
// Found it, allow the user to solve this thing
|
||||
BrowserActionActivity.launchUniversal(
|
||||
Injekt.get<Application>(),
|
||||
this,
|
||||
chain.request().url().toString()
|
||||
)
|
||||
}
|
||||
|
||||
return@addInterceptor rebuiltResponse
|
||||
}
|
||||
}
|
||||
response
|
||||
} else response
|
||||
}.build()
|
||||
|
||||
/**
|
||||
@@ -397,4 +393,14 @@ abstract class HttpSource : CatalogueSource {
|
||||
* Returns the list of filters for the source.
|
||||
*/
|
||||
override fun getFilterList() = FilterList()
|
||||
|
||||
// EXH -->
|
||||
private var delegate: DelegatedHttpSource? = null
|
||||
get() = if(Injekt.get<PreferencesHelper>().eh_delegateSources().getOrDefault())
|
||||
field
|
||||
else null
|
||||
fun bindDelegate(delegate: DelegatedHttpSource) {
|
||||
this.delegate = delegate
|
||||
}
|
||||
// EXH <--
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import exh.TSUMINO_SOURCE_ID
|
||||
import exh.ui.captcha.CaptchaCompletionVerifier
|
||||
import exh.ui.captcha.SolveCaptchaActivity
|
||||
import exh.ui.captcha.ActionCompletionVerifier
|
||||
import exh.ui.captcha.BrowserActionActivity
|
||||
import exh.metadata.metadata.TsuminoSearchMetadata
|
||||
import exh.metadata.metadata.TsuminoSearchMetadata.Companion.BASE_URL
|
||||
import exh.metadata.metadata.TsuminoSearchMetadata.Companion.TAG_TYPE_DEFAULT
|
||||
@@ -33,7 +33,7 @@ import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class Tsumino(private val context: Context): ParsedHttpSource(), LewdSource<TsuminoSearchMetadata, Document>, CaptchaCompletionVerifier {
|
||||
class Tsumino(private val context: Context): ParsedHttpSource(), LewdSource<TsuminoSearchMetadata, Document>, ActionCompletionVerifier {
|
||||
override val metaClass = TsuminoSearchMetadata::class
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
@@ -343,7 +343,7 @@ class Tsumino(private val context: Context): ParsedHttpSource(), LewdSource<Tsum
|
||||
else
|
||||
emptyMap()
|
||||
|
||||
SolveCaptchaActivity.launch(context,
|
||||
BrowserActionActivity.launchCaptcha(context,
|
||||
this,
|
||||
cookiesMap,
|
||||
CAPTCHA_SCRIPT,
|
||||
@@ -356,7 +356,7 @@ class Tsumino(private val context: Context): ParsedHttpSource(), LewdSource<Tsum
|
||||
}
|
||||
}
|
||||
|
||||
override fun verifyNoCaptcha(url: String): Boolean {
|
||||
override fun verifyComplete(url: String): Boolean {
|
||||
return Uri.parse(url).pathSegments.getOrNull(1) == "View"
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class SettingsAdvancedController : SettingsController() {
|
||||
title = "Enable delegated sources"
|
||||
key = PreferenceKeys.eh_delegateSources
|
||||
defaultValue = true
|
||||
summary = "Apply ${context.getString(R.string.app_name)} enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.joinToString { it.sourceName }}"
|
||||
summary = "Apply ${context.getString(R.string.app_name)} enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.map { it.sourceName }.distinct().joinToString()}"
|
||||
}
|
||||
|
||||
intListPreference {
|
||||
|
||||
Reference in New Issue
Block a user