From 18022713580d2b08480cc51f20d633fae5aaaa09 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Sun, 28 Mar 2021 03:19:01 +0430 Subject: [PATCH] fix chapters not being loaded correctly --- server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt | 10 ++++++++-- .../kotlin/ir/armor/tachidesk/server/JavalinSetup.kt | 9 +++++---- .../kotlin/ir/armor/tachidesk/server/ServerSetup.kt | 10 +++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt b/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt index 2784e37..3a3878c 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/impl/Page.kt @@ -28,10 +28,16 @@ fun getTrueImageUrl(page: Page, source: HttpSource): String { return page.imageUrl!! } -fun getPageImage(mangaId: Int, chapterId: Int, index: Int): Pair { +fun getPageImage(mangaId: Int, chapterIndex: Int, index: Int): Pair { val mangaEntry = transaction { MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!! } val source = getHttpSource(mangaEntry[MangaTable.sourceReference]) - val chapterEntry = transaction { ChapterTable.select { ChapterTable.id eq chapterId }.firstOrNull()!! } + val chapterEntry = transaction { + ChapterTable.select { + (ChapterTable.chapterIndex eq chapterIndex) and (ChapterTable.manga eq mangaId) + }.firstOrNull()!! + } + val chapterId = chapterEntry[ChapterTable.id].value + val pageEntry = transaction { PageTable.select { (PageTable.chapter eq chapterId) and (PageTable.index eq index) }.firstOrNull()!! } val tachiPage = Page( diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt index bef3367..3036195 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt @@ -60,7 +60,8 @@ fun javalinSetup() { openInBrowser() } - app.exception(NullPointerException::class.java) { _, ctx -> + app.exception(NullPointerException::class.java) { e, ctx -> + logger.error("NullPointerException while handling the request", e) ctx.status(404) } @@ -179,11 +180,11 @@ fun javalinSetup() { ctx.json(getChapter(chapterIndex, mangaId)) } - app.get("/api/v1/manga/:mangaId/chapter/:chapterId/page/:index") { ctx -> - val chapterId = ctx.pathParam("chapterId").toInt() + app.get("/api/v1/manga/:mangaId/chapter/:chapterIndex/page/:index") { ctx -> val mangaId = ctx.pathParam("mangaId").toInt() + val chapterIndex = ctx.pathParam("chapterIndex").toInt() val index = ctx.pathParam("index").toInt() - val result = getPageImage(mangaId, chapterId, index) + val result = getPageImage(mangaId, chapterIndex, index) ctx.result(result.first) ctx.header("content-type", result.second) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt index 0ae2961..3778d1b 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt @@ -40,7 +40,7 @@ val androidCompat by lazy { AndroidCompat() } fun applicationSetup() { // register server config GlobalConfigManager.registerModule( - ServerConfig.register(GlobalConfigManager.config) + ServerConfig.register(GlobalConfigManager.config) ) // set application wide logging level @@ -50,10 +50,10 @@ fun applicationSetup() { // make dirs we need listOf( - applicationDirs.dataRoot, - applicationDirs.extensionsRoot, - "${applicationDirs.extensionsRoot}/icon", - applicationDirs.thumbnailsRoot + applicationDirs.dataRoot, + applicationDirs.extensionsRoot, + "${applicationDirs.extensionsRoot}/icon", + applicationDirs.thumbnailsRoot ).forEach { File(it).mkdirs() }