Minor cleanup
(cherry picked from commit b71b9ab5518d9c8b3ec4c24b791ed35f1a44e8e0)
This commit is contained in:
parent
cdf2cf8a2d
commit
c58554ec75
@ -13,8 +13,8 @@ import kotlinx.coroutines.CancellationException
|
|||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
class MangaDexLoginHelper(authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
||||||
val authService by authServiceLazy
|
private val authService by authServiceLazy
|
||||||
suspend fun isAuthenticated(): Boolean {
|
suspend fun isAuthenticated(): Boolean {
|
||||||
return runCatching { authService.checkToken().isAuthenticated }
|
return runCatching { authService.checkToken().isAuthenticated }
|
||||||
.getOrElse { e ->
|
.getOrElse { e ->
|
||||||
|
@ -7,12 +7,17 @@ import okhttp3.Authenticator
|
|||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.Route
|
import okhttp3.Route
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class TokenAuthenticator(private val loginHelper: MangaDexLoginHelper) : Authenticator {
|
class TokenAuthenticator(private val loginHelper: MangaDexLoginHelper) : Authenticator {
|
||||||
override fun authenticate(route: Route?, response: Response): Request? {
|
override fun authenticate(route: Route?, response: Response): Request? {
|
||||||
xLogI("Detected Auth error ${response.code} on ${response.request.url}")
|
xLogI("Detected Auth error ${response.code} on ${response.request.url}")
|
||||||
|
|
||||||
val token = refreshToken(loginHelper)
|
val token = try {
|
||||||
|
refreshToken(loginHelper)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw IOException(e)
|
||||||
|
}
|
||||||
return if (token != null) {
|
return if (token != null) {
|
||||||
response.request.newBuilder().header("Authorization", token).build()
|
response.request.newBuilder().header("Authorization", token).build()
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,8 +20,8 @@ fun OkHttpClient.Builder.injectPatches(sourceIdProducer: () -> Long): OkHttpClie
|
|||||||
|
|
||||||
fun findAndApplyPatches(sourceId: Long): EHInterceptor {
|
fun findAndApplyPatches(sourceId: Long): EHInterceptor {
|
||||||
// TODO make it so captcha doesnt auto open in manga eden while applying universal interceptors
|
// TODO make it so captcha doesnt auto open in manga eden while applying universal interceptors
|
||||||
return if (Injekt.get<PreferencesHelper>().autoSolveCaptcha().get()) ((EH_INTERCEPTORS[sourceId].orEmpty()) + (EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR].orEmpty())).merge()
|
return if (Injekt.get<PreferencesHelper>().autoSolveCaptcha().get()) (EH_INTERCEPTORS[sourceId].orEmpty() + EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR].orEmpty()).merge()
|
||||||
else (EH_INTERCEPTORS[sourceId].orEmpty()).merge()
|
else EH_INTERCEPTORS[sourceId].orEmpty().merge()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<EHInterceptor>.merge(): EHInterceptor {
|
fun List<EHInterceptor>.merge(): EHInterceptor {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user