mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-26 02:48:24 +01:00
fix: slightly optimised the function of string to number conversion and fixed the check
This commit is contained in:
parent
e332a5018e
commit
23a34cd3b7
@ -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<HKAuthTokenInfo>(authTokenInfoResponse.body.string())
|
||||
setAuth(HKOAuth(oauth!!.accessToken, authTokenInfo.expiration))
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user