LibGroup: fix crash on null token (#4071)

fix crash on null token
This commit is contained in:
nedius 2024-07-18 13:48:04 +03:00 committed by Draff
parent b28987c34c
commit 1ca13b4697
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 13 additions and 7 deletions

View File

@ -2,4 +2,4 @@ plugins {
id("lib-multisrc")
}
baseVersionCode = 29
baseVersionCode = 30

View File

@ -188,7 +188,11 @@ abstract class LibGroup(
} else {
it.replace("\\", "")
}
returnValue = str.parseAs<AuthToken>()
str.parseAs<AuthToken>().let { auth ->
if (auth.isValid()) {
returnValue = auth
}
}
}
latch.countDown()
}

View File

@ -266,8 +266,8 @@ class Pages(
@Serializable
class AuthToken(
private val auth: Auth,
private val token: Token,
private val auth: Auth?,
private val token: Token?,
) {
@Serializable
class Auth(
@ -282,13 +282,15 @@ class AuthToken(
@SerialName("access_token") val accessToken: String,
)
fun isValid(): Boolean = auth != null && token != null
fun isExpired(): Boolean {
val currentTime = System.currentTimeMillis()
val expiresIn = token.timestamp + (token.expiresIn * 1000)
val expiresIn = token!!.timestamp + (token.expiresIn * 1000)
return expiresIn < currentTime
}
fun getToken(): String = "${token.tokenType} ${token.accessToken}"
fun getToken(): String = "${token!!.tokenType} ${token.accessToken}"
fun getUserId(): Int = auth.id
fun getUserId(): Int = auth!!.id
}