Minor cleanup

(cherry picked from commit b71b9ab5518d9c8b3ec4c24b791ed35f1a44e8e0)
This commit is contained in:
Jobobby04 2022-06-03 19:08:15 -04:00
parent cdf2cf8a2d
commit c58554ec75
3 changed files with 10 additions and 5 deletions

View File

@ -13,8 +13,8 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.withTimeoutOrNull
import kotlin.time.Duration.Companion.seconds
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
val authService by authServiceLazy
class MangaDexLoginHelper(authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
private val authService by authServiceLazy
suspend fun isAuthenticated(): Boolean {
return runCatching { authService.checkToken().isAuthenticated }
.getOrElse { e ->

View File

@ -7,12 +7,17 @@ import okhttp3.Authenticator
import okhttp3.Request
import okhttp3.Response
import okhttp3.Route
import java.io.IOException
class TokenAuthenticator(private val loginHelper: MangaDexLoginHelper) : Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
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) {
response.request.newBuilder().header("Authorization", token).build()
} else {

View File

@ -20,8 +20,8 @@ fun OkHttpClient.Builder.injectPatches(sourceIdProducer: () -> Long): OkHttpClie
fun findAndApplyPatches(sourceId: Long): EHInterceptor {
// 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()
else (EH_INTERCEPTORS[sourceId].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()
}
fun List<EHInterceptor>.merge(): EHInterceptor {