parent
b28987c34c
commit
1ca13b4697
|
@ -2,4 +2,4 @@ plugins {
|
||||||
id("lib-multisrc")
|
id("lib-multisrc")
|
||||||
}
|
}
|
||||||
|
|
||||||
baseVersionCode = 29
|
baseVersionCode = 30
|
||||||
|
|
|
@ -188,7 +188,11 @@ abstract class LibGroup(
|
||||||
} else {
|
} else {
|
||||||
it.replace("\\", "")
|
it.replace("\\", "")
|
||||||
}
|
}
|
||||||
returnValue = str.parseAs<AuthToken>()
|
str.parseAs<AuthToken>().let { auth ->
|
||||||
|
if (auth.isValid()) {
|
||||||
|
returnValue = auth
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
latch.countDown()
|
latch.countDown()
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,8 +266,8 @@ class Pages(
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class AuthToken(
|
class AuthToken(
|
||||||
private val auth: Auth,
|
private val auth: Auth?,
|
||||||
private val token: Token,
|
private val token: Token?,
|
||||||
) {
|
) {
|
||||||
@Serializable
|
@Serializable
|
||||||
class Auth(
|
class Auth(
|
||||||
|
@ -282,13 +282,15 @@ class AuthToken(
|
||||||
@SerialName("access_token") val accessToken: String,
|
@SerialName("access_token") val accessToken: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun isValid(): Boolean = auth != null && token != null
|
||||||
|
|
||||||
fun isExpired(): Boolean {
|
fun isExpired(): Boolean {
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
val expiresIn = token.timestamp + (token.expiresIn * 1000)
|
val expiresIn = token!!.timestamp + (token.expiresIn * 1000)
|
||||||
return expiresIn < currentTime
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue