fix: slightly optimised the function of string to number conversion and fixed the check

This commit is contained in:
Lorg0n 2024-10-27 01:02:16 +03:00
parent e332a5018e
commit 23a34cd3b7
2 changed files with 9 additions and 10 deletions

View File

@ -18,13 +18,16 @@ class HikkaInterceptor(private val hikka: Hikka) : Interceptor {
if (currAuth.isExpired()) { if (currAuth.isExpired()) {
val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken)) val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken))
if (!refreshTokenResponse.isSuccessful) if (!refreshTokenResponse.isSuccessful) {
throw Exception("Hikka: The token is expired")
refreshTokenResponse.close() refreshTokenResponse.close()
hikka.logout()
throw Exception("Hikka: The token is expired")
}
val authTokenInfoResponse = chain.proceed(HikkaApi.authTokenInfo(currAuth.accessToken)) val authTokenInfoResponse = chain.proceed(HikkaApi.authTokenInfo(currAuth.accessToken))
if (!authTokenInfoResponse.isSuccessful) if (!authTokenInfoResponse.isSuccessful) {
authTokenInfoResponse.close() authTokenInfoResponse.close()
}
val authTokenInfo = json.decodeFromString<HKAuthTokenInfo>(authTokenInfoResponse.body.string()) val authTokenInfo = json.decodeFromString<HKAuthTokenInfo>(authTokenInfoResponse.body.string())
setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration)) setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration))

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.data.track.hikka package eu.kanade.tachiyomi.data.track.hikka
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import java.security.MessageDigest import java.util.UUID
fun Track.toApiStatus() = when (status) { fun Track.toApiStatus() = when (status) {
Hikka.READING -> "reading" Hikka.READING -> "reading"
@ -23,10 +23,6 @@ fun toTrackStatus(status: String) = when (status) {
} }
fun stringToNumber(input: String): Long { fun stringToNumber(input: String): Long {
val digest = MessageDigest.getInstance("SHA-256") val uuid = UUID.nameUUIDFromBytes(input.toByteArray())
val hash = digest.digest(input.toByteArray()) return uuid.mostSignificantBits and Long.MAX_VALUE
return hash.copyOfRange(0, 8).fold(0L) { acc, byte ->
acc shl 8 or (byte.toLong() and 0xff)
}
} }