Fix Hikka search failing due to unclosed response & show toast on remote-removed titles (#3548)
* Fix Hikka search failing due to unclosed response This closes #3547. I have also included a precautionary refactor of the `getRead` method in HikkaApi.kt, which by the looks of it _could_ leak an unclosed response as well. The try/catch with awaitSuccess pattern has been used in this same way in the Bangumi and MangaBaka implementations as well. The benefit here is that `awaitSuccess()` closes the response on error before throwing an `HttpException`. * Show toast on remote-removed list entries
This commit is contained in:
@@ -125,14 +125,13 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
||||
track.copyPersonalFrom(remoteTrack)
|
||||
track.total_chapters = remoteTrack.total_chapters
|
||||
|
||||
val readContent = api.getRead(track)
|
||||
if (readContent != null) {
|
||||
track.score = readContent.score.toDouble()
|
||||
track.last_chapter_read = readContent.chapters.toDouble()
|
||||
track.status = toTrackStatus(readContent.status)
|
||||
track.started_reading_date = (readContent.startDate ?: 0L) * 1000
|
||||
track.finished_reading_date = (readContent.endDate ?: 0L) * 1000
|
||||
}
|
||||
val readContent = api.getRead(track) ?: throw Exception("Could not find manga")
|
||||
|
||||
track.score = readContent.score.toDouble()
|
||||
track.last_chapter_read = readContent.chapters.toDouble()
|
||||
track.status = toTrackStatus(readContent.status)
|
||||
track.started_reading_date = (readContent.startDate ?: 0L) * 1000
|
||||
track.finished_reading_date = (readContent.endDate ?: 0L) * 1000
|
||||
|
||||
return track
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.track.hikka.dto.HKUser
|
||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||
import eu.kanade.tachiyomi.network.DELETE
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.HttpException
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.PUT
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
@@ -103,12 +104,16 @@ class HikkaApi(
|
||||
val slug = track.tracking_url.split("/")[4]
|
||||
val url = "$BASE_API_URL/read/manga/$slug".toUri().buildUpon().build()
|
||||
with(json) {
|
||||
val response = authClient.newCall(GET(url.toString())).execute()
|
||||
if (response.code == 404) {
|
||||
return@withIOContext null
|
||||
}
|
||||
response.use {
|
||||
it.parseAs<HKRead>()
|
||||
try {
|
||||
authClient.newCall(GET(url.toString()))
|
||||
.awaitSuccess()
|
||||
.parseAs<HKRead>()
|
||||
} catch (e: HttpException) {
|
||||
if (e.code == 404) {
|
||||
null
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,14 @@ class HikkaInterceptor(private val hikka: Hikka) : Interceptor {
|
||||
refreshTokenResponse.close()
|
||||
hikka.logout()
|
||||
throw Exception("Hikka: The token is expired")
|
||||
} else {
|
||||
refreshTokenResponse.close()
|
||||
}
|
||||
|
||||
val authTokenInfoResponse = chain.proceed(HikkaApi.authTokenInfo(currAuth.accessToken))
|
||||
if (!authTokenInfoResponse.isSuccessful) {
|
||||
authTokenInfoResponse.close()
|
||||
throw Exception("Hikka: Auth token info failed")
|
||||
}
|
||||
|
||||
val authTokenInfo = json.decodeFromString<HKAuthTokenInfo>(authTokenInfoResponse.body.string())
|
||||
|
||||
Reference in New Issue
Block a user