Maybe fix a few crashes related to mangadex logins
This commit is contained in:
parent
f76c48c8ae
commit
be52ea6f18
@ -12,7 +12,6 @@ import exh.md.utils.MdUtil
|
|||||||
import exh.util.seconds
|
import exh.util.seconds
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
|
|
||||||
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
|
||||||
val authService by authServiceLazy
|
val authService by authServiceLazy
|
||||||
@ -31,7 +30,7 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
|||||||
}
|
}
|
||||||
val refresh = runCatching {
|
val refresh = runCatching {
|
||||||
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
|
val jsonResponse = authService.refreshToken(RefreshTokenDto(refreshToken))
|
||||||
preferences.trackToken(mdList).set(MdUtil.jsonParser.encodeToString(jsonResponse.token))
|
MdUtil.updateLoginToken(jsonResponse.token, preferences, mdList)
|
||||||
}
|
}
|
||||||
|
|
||||||
val e = refresh.exceptionOrNull()
|
val e = refresh.exceptionOrNull()
|
||||||
@ -52,12 +51,16 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
|
|||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
|
|
||||||
val loginResponseDto = loginResult.getOrNull()
|
val loginResponseDto = loginResult.getOrNull()
|
||||||
MdUtil.updateLoginToken(
|
if (loginResponseDto != null) {
|
||||||
loginResponseDto?.token,
|
MdUtil.updateLoginToken(
|
||||||
preferences,
|
loginResponseDto.token,
|
||||||
mdList
|
preferences,
|
||||||
)
|
mdList
|
||||||
loginResponseDto != null
|
)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -300,10 +300,8 @@ class MdUtil {
|
|||||||
|
|
||||||
fun refreshToken(preferences: PreferencesHelper, mdList: MdList) = getLoginBody(preferences, mdList)?.refresh
|
fun refreshToken(preferences: PreferencesHelper, mdList: MdList) = getLoginBody(preferences, mdList)?.refresh
|
||||||
|
|
||||||
fun updateLoginToken(token: LoginBodyTokenDto?, preferences: PreferencesHelper, mdList: MdList) {
|
fun updateLoginToken(token: LoginBodyTokenDto, preferences: PreferencesHelper, mdList: MdList) {
|
||||||
if (token != null) {
|
preferences.trackToken(mdList).set(jsonParser.encodeToString(token))
|
||||||
preferences.trackToken(mdList).set(jsonParser.encodeToString(token))
|
|
||||||
} else preferences.trackToken(mdList).delete()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAuthHeaders(headers: Headers, preferences: PreferencesHelper, mdList: MdList) =
|
fun getAuthHeaders(headers: Headers, preferences: PreferencesHelper, mdList: MdList) =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user