Fix DTO API for MangaDex tracker
This commit is contained in:
parent
a4d556affc
commit
66077917af
3 changed files with 19 additions and 19 deletions
|
|
@ -2,7 +2,7 @@ package exh.md.network
|
|||
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.OAuth
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.dto.MALOAuth
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
import exh.md.utils.MdUtil
|
||||
import exh.util.nullIfBlank
|
||||
|
|
@ -18,7 +18,7 @@ class MangaDexAuthInterceptor(
|
|||
|
||||
var token = trackPreferences.trackToken(mdList).get().nullIfBlank()
|
||||
|
||||
private var oauth: OAuth? = null
|
||||
private var oauth: MALOAuth? = null
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val originalRequest = chain.request()
|
||||
|
|
@ -40,7 +40,7 @@ class MangaDexAuthInterceptor(
|
|||
|
||||
// Add the authorization header to the original request
|
||||
val authRequest = originalRequest.newBuilder()
|
||||
.addHeader("Authorization", "Bearer ${oauth!!.access_token}")
|
||||
.addHeader("Authorization", "Bearer ${oauth!!.accessToken}")
|
||||
.build()
|
||||
|
||||
val response = chain.proceed(authRequest)
|
||||
|
|
@ -57,7 +57,7 @@ class MangaDexAuthInterceptor(
|
|||
response.close()
|
||||
|
||||
val newRequest = originalRequest.newBuilder()
|
||||
.addHeader("Authorization", "Bearer ${newToken.access_token}")
|
||||
.addHeader("Authorization", "Bearer ${newToken.accessToken}")
|
||||
.build()
|
||||
|
||||
return chain.proceed(newRequest)
|
||||
|
|
@ -70,18 +70,18 @@ class MangaDexAuthInterceptor(
|
|||
* Called when the user authenticates with MangaDex for the first time. Sets the refresh token
|
||||
* and the oauth object.
|
||||
*/
|
||||
fun setAuth(oauth: OAuth?) {
|
||||
token = oauth?.access_token
|
||||
fun setAuth(oauth: MALOAuth?) {
|
||||
token = oauth?.accessToken
|
||||
this.oauth = oauth
|
||||
MdUtil.saveOAuth(trackPreferences, mdList, oauth)
|
||||
}
|
||||
|
||||
private fun refreshToken(chain: Interceptor.Chain): OAuth? {
|
||||
private fun refreshToken(chain: Interceptor.Chain): MALOAuth? {
|
||||
val newOauth = runCatching {
|
||||
val oauthResponse = chain.proceed(MdUtil.refreshTokenRequest(oauth!!))
|
||||
|
||||
if (oauthResponse.isSuccessful) {
|
||||
with(MdUtil.jsonParser) { oauthResponse.parseAs<OAuth>() }
|
||||
with(MdUtil.jsonParser) { oauthResponse.parseAs<MALOAuth>() }
|
||||
} else {
|
||||
oauthResponse.close()
|
||||
null
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package exh.md.network
|
|||
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.OAuth
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.dto.MALOAuth
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
|
|
@ -38,7 +38,7 @@ class MangaDexLoginHelper(
|
|||
val data = with(MdUtil.jsonParser) {
|
||||
client.newCall(
|
||||
POST(MdApi.baseAuthUrl + MdApi.token, body = loginFormBody),
|
||||
).awaitSuccess().parseAs<OAuth>()
|
||||
).awaitSuccess().parseAs<MALOAuth>()
|
||||
}
|
||||
mangaDexAuthInterceptor.setAuth(data)
|
||||
}.exceptionOrNull()
|
||||
|
|
@ -55,8 +55,8 @@ class MangaDexLoginHelper(
|
|||
|
||||
suspend fun logout(): Boolean {
|
||||
val oauth = MdUtil.loadOAuth(preferences, mdList)
|
||||
val sessionToken = oauth?.access_token
|
||||
val refreshToken = oauth?.refresh_token
|
||||
val sessionToken = oauth?.accessToken
|
||||
val refreshToken = oauth?.refreshToken
|
||||
if (refreshToken.isNullOrEmpty() || sessionToken.isNullOrEmpty()) {
|
||||
mdList.logout()
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package exh.md.utils
|
|||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.domain.track.service.TrackPreferences
|
||||
import eu.kanade.tachiyomi.data.track.mdlist.MdList
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.OAuth
|
||||
import eu.kanade.tachiyomi.data.track.myanimelist.dto.MALOAuth
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
|
|
@ -189,7 +189,7 @@ class MdUtil {
|
|||
return "$cdnUrl/covers/$dexId/$fileName"
|
||||
}
|
||||
|
||||
fun saveOAuth(preferences: TrackPreferences, mdList: MdList, oAuth: OAuth?) {
|
||||
fun saveOAuth(preferences: TrackPreferences, mdList: MdList, oAuth: MALOAuth?) {
|
||||
if (oAuth == null) {
|
||||
preferences.trackToken(mdList).delete()
|
||||
} else {
|
||||
|
|
@ -197,9 +197,9 @@ class MdUtil {
|
|||
}
|
||||
}
|
||||
|
||||
fun loadOAuth(preferences: TrackPreferences, mdList: MdList): OAuth? {
|
||||
fun loadOAuth(preferences: TrackPreferences, mdList: MdList): MALOAuth? {
|
||||
return try {
|
||||
jsonParser.decodeFromString<OAuth>(preferences.trackToken(mdList).get())
|
||||
jsonParser.decodeFromString<MALOAuth>(preferences.trackToken(mdList).get())
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
|
@ -207,11 +207,11 @@ class MdUtil {
|
|||
|
||||
private var codeVerifier: String? = null
|
||||
|
||||
fun refreshTokenRequest(oauth: OAuth): Request {
|
||||
fun refreshTokenRequest(oauth: MALOAuth): Request {
|
||||
val formBody = FormBody.Builder()
|
||||
.add("client_id", MdConstants.Login.clientId)
|
||||
.add("grant_type", MdConstants.Login.refreshToken)
|
||||
.add("refresh_token", oauth.refresh_token)
|
||||
.add("refresh_token", oauth.refreshToken)
|
||||
.add("code_verifier", getPkceChallengeCode())
|
||||
.add("redirect_uri", MdConstants.Login.redirectUri)
|
||||
.build()
|
||||
|
|
@ -220,7 +220,7 @@ class MdUtil {
|
|||
// request is called by the interceptor itself so it doesn't reach
|
||||
// the part where the token is added automatically.
|
||||
val headers = Headers.Builder()
|
||||
.add("Authorization", "Bearer ${oauth.access_token}")
|
||||
.add("Authorization", "Bearer ${oauth.accessToken}")
|
||||
.build()
|
||||
|
||||
return POST(MdApi.baseAuthUrl + MdApi.token, body = formBody, headers = headers)
|
||||
|
|
|
|||
Loading…
Reference in a new issue