diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt index fe9335d8..ff25f0f9 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt @@ -7,6 +7,7 @@ package suwayomi.tachidesk.manga.impl * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource import org.jetbrains.exposed.sql.and @@ -68,6 +69,13 @@ object Page { } } + // don't cache images for Local Source + if (mangaEntry[MangaTable.sourceReference] == LocalSource.ID) { + return CachedImageResponse.getImageResponse { + source.fetchImage(tachiyomiPage).awaitSingle() + } + } + val chapterDir = getChapterDir(mangaId, chapterId) File(chapterDir).mkdirs() val fileName = getPageName(index, chapterDir) // e.g. 001 diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/storage/CachedImageResponse.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/storage/CachedImageResponse.kt index 6cb2dd8c..783acda2 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/storage/CachedImageResponse.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/storage/CachedImageResponse.kt @@ -68,4 +68,22 @@ object CachedImageResponse { File(it).delete() } } + + suspend fun getImageResponse(fetcher: suspend () -> Response): Pair { + val response = fetcher() + + if (response.code == 200) { + val responseBytes = response.body!!.bytes() + + // find image type + val imageType = response.headers["content-type"] + ?: ImageUtil.findImageType { responseBytes.inputStream() }?.mime + ?: "image/jpeg" + + return responseBytes.inputStream() to imageType + } else { + response.closeQuietly() + throw Exception("request error! ${response.code}") + } + } }