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 60f09eba..8c938ce1 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Page.kt @@ -48,7 +48,6 @@ object Page { progressFlow: ((StateFlow) -> Unit)? = null, ): Pair { val mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() } - val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference]) val chapterEntry = transaction { ChapterTable @@ -60,6 +59,14 @@ object Page { } val chapterId = chapterEntry[ChapterTable.id].value + try { + if (chapterEntry[ChapterTable.isDownloaded]) { + return ChapterDownloadHelper.getImage(mangaId, chapterId, index) + } + } catch (_: Exception) { + // ignore and fetch again + } + val pageEntry = transaction { PageTable @@ -79,7 +86,7 @@ object Page { progressFlow?.invoke(tachiyomiPage.progress) // we treat Local source differently - if (source.id == LocalSource.ID) { + if (mangaEntry[MangaTable.sourceReference] == LocalSource.ID) { // is of archive format if (LocalSource.pageCache.containsKey(chapterEntry[ChapterTable.url])) { val pageStream = LocalSource.pageCache[chapterEntry[ChapterTable.url]]!![index] @@ -91,6 +98,7 @@ object Page { return imageFile.inputStream() to (ImageUtil.findImageType { imageFile.inputStream() }?.mime ?: "image/jpeg") } + val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference]) source as HttpSource if (pageEntry[PageTable.imageUrl] == null) { @@ -104,14 +112,6 @@ object Page { val fileName = getPageName(index) - try { - if (chapterEntry[ChapterTable.isDownloaded]) { - return ChapterDownloadHelper.getImage(mangaId, chapterId, index) - } - } catch (_: Exception) { - // ignore and fetch again - } - val cacheSaveDir = getChapterCachePath(mangaId, chapterId) // Note: don't care about invalidating cache because OS cache is not permanent