diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt index b84d619b..b1e0cbca 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/MangaController.kt @@ -466,21 +466,27 @@ object MangaController { behaviorOf = { ctx, mangaId, chapterIndex, index, updateProgress, format -> ctx.getAttribute(Attribute.TachideskUser).requireUser() ctx.future { - future { Page.getPageImage(mangaId, chapterIndex, index, format, null) } - .thenApply { - ctx.header("content-type", it.second) - val httpCacheSeconds = 1.days.inWholeSeconds - ctx.header("cache-control", "max-age=$httpCacheSeconds") - ctx.result(it.first) + future { + Page.getPageImage( + mangaId = mangaId, + chapterIndex = chapterIndex, + index = index, + format = format, + ) + }.thenApply { + ctx.header("content-type", it.second) + val httpCacheSeconds = 1.days.inWholeSeconds + ctx.header("cache-control", "max-age=$httpCacheSeconds") + ctx.result(it.first) - if (updateProgress == true) { - val chapterId = Chapter.updateChapterProgress(mangaId, chapterIndex, pageNo = index) - // Sync progress with KoreaderSync if chapter update was successful - if (chapterId != -1) { - GlobalScope.launch { KoreaderSyncService.pushProgress(chapterId) } - } + if (updateProgress == true) { + val chapterId = Chapter.updateChapterProgress(mangaId, chapterIndex, pageNo = index) + // Sync progress with KoreaderSync if chapter update was successful + if (chapterId != -1) { + GlobalScope.launch { KoreaderSyncService.pushProgress(chapterId) } } } + } } }, withResults = { 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 ffdef3fd..b46792a0 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,8 @@ object Page { suspend fun getPageImage( mangaId: Int, - chapterId: Int, + chapterId: Int? = null, + chapterIndex: Int? = null, index: Int, format: String? = null, progressFlow: ((StateFlow) -> Unit)? = null, @@ -56,10 +57,17 @@ object Page { val mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() } val chapterEntry = transaction { - ChapterTable - .selectAll() - .where { ChapterTable.id eq chapterId } - .first() + if (chapterId != null) { + ChapterTable + .selectAll() + .where { ChapterTable.id eq chapterId } + .first() + } else { + ChapterTable + .selectAll() + .where { ChapterTable.manga eq mangaId and (ChapterTable.sourceOrder eq chapterIndex!!) } + .first() + } } val chapterId = chapterEntry[ChapterTable.id].value