From 23a34cd3b705b6e466bd250b3beadf23433c45ee Mon Sep 17 00:00:00 2001 From: Lorg0n Date: Sun, 27 Oct 2024 01:02:16 +0300 Subject: [PATCH] fix: slightly optimised the function of string to number conversion and fixed the check --- .../tachiyomi/data/track/hikka/HikkaInterceptor.kt | 9 ++++++--- .../eu/kanade/tachiyomi/data/track/hikka/HikkaUtils.kt | 10 +++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt index db19db4ea..e555ab3cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaInterceptor.kt @@ -18,13 +18,16 @@ class HikkaInterceptor(private val hikka: Hikka) : Interceptor { if (currAuth.isExpired()) { val refreshTokenResponse = chain.proceed(HikkaApi.refreshTokenRequest(currAuth.accessToken)) - if (!refreshTokenResponse.isSuccessful) - throw Exception("Hikka: The token is expired") + if (!refreshTokenResponse.isSuccessful) { refreshTokenResponse.close() + hikka.logout() + throw Exception("Hikka: The token is expired") + } val authTokenInfoResponse = chain.proceed(HikkaApi.authTokenInfo(currAuth.accessToken)) - if (!authTokenInfoResponse.isSuccessful) + if (!authTokenInfoResponse.isSuccessful) { authTokenInfoResponse.close() + } val authTokenInfo = json.decodeFromString(authTokenInfoResponse.body.string()) setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaUtils.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaUtils.kt index a4363c128..a31b692c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaUtils.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/HikkaUtils.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.data.track.hikka import eu.kanade.tachiyomi.data.database.models.Track -import java.security.MessageDigest +import java.util.UUID fun Track.toApiStatus() = when (status) { Hikka.READING -> "reading" @@ -23,10 +23,6 @@ fun toTrackStatus(status: String) = when (status) { } fun stringToNumber(input: String): Long { - val digest = MessageDigest.getInstance("SHA-256") - val hash = digest.digest(input.toByteArray()) - - return hash.copyOfRange(0, 8).fold(0L) { acc, byte -> - acc shl 8 or (byte.toLong() and 0xff) - } + val uuid = UUID.nameUUIDFromBytes(input.toByteArray()) + return uuid.mostSignificantBits and Long.MAX_VALUE }