Skip to content

Commit

Permalink
Add missing @EncodeDefault annotation to MALOAuth
Browse files Browse the repository at this point in the history
Similar to the situation with Bangumi, the missing annotation means
kotlinx.serialization would _provide_ the default value upon
instantiation but not serialise it to disk. This means the isExpired()
calculation would effectively rarely/never do its job correctly,
leading to Mihon sending expired tokens to MAL and causing problems
for everyone involved.

Overall, this change _could_ (should) lead to a drastic reduction in
MAL requests failing, leading to users having to relink their MAL
accounts.

Also switched createdAt to be in seconds instead of milliseconds as
all other trackers use seconds for timestamps (except for AniList,
which uses milliseconds but doesn't use a createdAt timestamp anyway).
  • Loading branch information
MajorTanya committed Jan 30, 2025
1 parent dce6aac commit 22db8d3
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.data.track.myanimelist.dto

import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -14,10 +15,11 @@ data class MALOAuth(
@SerialName("expires_in")
val expiresIn: Long,
@SerialName("created_at")
val createdAt: Long = System.currentTimeMillis(),
@EncodeDefault
val createdAt: Long = System.currentTimeMillis() / 1000,
) {
// Assumes expired a minute earlier
private val adjustedExpiresIn: Long = (expiresIn - 60) * 1000
private val adjustedExpiresIn: Long = (expiresIn - 60)

fun isExpired() = createdAt + adjustedExpiresIn < System.currentTimeMillis()
fun isExpired() = createdAt + adjustedExpiresIn < System.currentTimeMillis() / 1000
}

0 comments on commit 22db8d3

Please sign in to comment.