mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
This commit is contained in:
parent
f0053a2f78
commit
491d476cac
@ -112,11 +112,7 @@ class Myanimelist(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
.toCompletable()
|
.toCompletable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to login again if cookies have been cleared but credentials are still filled
|
fun refreshLogin() {
|
||||||
fun ensureLoggedIn() {
|
|
||||||
if (isAuthorized) return
|
|
||||||
if (!isLogged) throw Exception("MAL Login Credentials not found")
|
|
||||||
|
|
||||||
val username = getUsername()
|
val username = getUsername()
|
||||||
val password = getPassword()
|
val password = getPassword()
|
||||||
logout()
|
logout()
|
||||||
@ -131,6 +127,14 @@ class Myanimelist(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to login again if cookies have been cleared but credentials are still filled
|
||||||
|
fun ensureLoggedIn() {
|
||||||
|
if (isAuthorized) return
|
||||||
|
if (!isLogged) throw Exception("MAL Login Credentials not found")
|
||||||
|
|
||||||
|
refreshLogin()
|
||||||
|
}
|
||||||
|
|
||||||
override fun logout() {
|
override fun logout() {
|
||||||
super.logout()
|
super.logout()
|
||||||
preferences.trackToken(this).delete()
|
preferences.trackToken(this).delete()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.data.track.myanimelist
|
package eu.kanade.tachiyomi.data.track.myanimelist
|
||||||
|
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Request
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
@ -11,18 +12,27 @@ class MyAnimeListInterceptor(private val myanimelist: Myanimelist): Interceptor
|
|||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
myanimelist.ensureLoggedIn()
|
myanimelist.ensureLoggedIn()
|
||||||
|
|
||||||
var request = chain.request()
|
val request = chain.request()
|
||||||
request.body()?.let {
|
var response = chain.proceed(updateRequest(request))
|
||||||
|
|
||||||
|
if (response.code() == 400){
|
||||||
|
myanimelist.refreshLogin()
|
||||||
|
response = chain.proceed(updateRequest(request))
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRequest(request: Request): Request {
|
||||||
|
return request.body()?.let {
|
||||||
val contentType = it.contentType().toString()
|
val contentType = it.contentType().toString()
|
||||||
val updatedBody = when {
|
val updatedBody = when {
|
||||||
contentType.contains("x-www-form-urlencoded") -> updateFormBody(it)
|
contentType.contains("x-www-form-urlencoded") -> updateFormBody(it)
|
||||||
contentType.contains("json") -> updateJsonBody(it)
|
contentType.contains("json") -> updateJsonBody(it)
|
||||||
else -> it
|
else -> it
|
||||||
}
|
}
|
||||||
request = request.newBuilder().post(updatedBody).build()
|
request.newBuilder().post(updatedBody).build()
|
||||||
}
|
} ?: request
|
||||||
|
|
||||||
return chain.proceed(request)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bodyToString(requestBody: RequestBody): String {
|
private fun bodyToString(requestBody: RequestBody): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user