From b4b3a4d2869fae7839b4b3111e289056e33cfea8 Mon Sep 17 00:00:00 2001 From: Two-Ai <81279822+Two-Ai@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:18:12 -0500 Subject: [PATCH] Fixup HttpPageLoader _loadPage (#8984) Fixup for e4bc8990 (#8955) HttpSource.fetchImage() uses Call.asObservableSuccess(), which cancels the call on unsubscribe. This causes the call to be cancelled before it is used, leading to a "java.net.SocketException: Socket is closed" when trying to use the response in putImageToCache(). To fix this, use Call.awaitSuccess() via a new HttpSource.getImage() suspending function. This addition to source-api is only intended for app use, so it will not be added to the extensions-api stubs. --- .../tachiyomi/ui/reader/loader/HttpPageLoader.kt | 2 +- .../eu/kanade/tachiyomi/source/online/HttpSource.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt index 4d5480fa6..780d21bf7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt @@ -200,7 +200,7 @@ class HttpPageLoader( if (!chapterCache.isImageInCache(imageUrl)) { page.status = Page.State.DOWNLOAD_IMAGE - val imageResponse = source.fetchImage(page).awaitSingle() + val imageResponse = source.getImage(page) chapterCache.putImageToCache(imageUrl, imageResponse) } diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index a43e84ff8..10612d410 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.source.online import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.asObservableSuccess +import eu.kanade.tachiyomi.network.awaitSuccess import eu.kanade.tachiyomi.network.newCachelessCallWithProgress import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.FilterList @@ -305,6 +306,17 @@ abstract class HttpSource : CatalogueSource { .asObservableSuccess() } + /** + * Returns the response of the source image. + * + * @param page the page whose source image has to be downloaded. + */ + suspend fun getImage(page: Page): Response { + // images will be cached or saved manually, so don't take up network cache + return client.newCachelessCallWithProgress(imageRequest(page), page) + .awaitSuccess() + } + /** * Returns the request for getting the source image. Override only if it's needed to override * the url, send different headers or request method like POST.