mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
Feature/graphql chapter pages mutation handle downloaded chapters (#665)
* Update chapter page refresh logic with logic from "ChapterMutation" * Rename function to "getChapterDownloadReadyByIndex" * Update "ChapterForDownload" to work with only "chapterId" being passed * Return database chapter page list in case chapter is downloaded In case the chapter is downloaded, fetching the chapter pages info should not be needed. It should also currently break reading downloaded chapters while being offline, since the page request will always fail, since there is no internet connection
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.batchInsert
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@@ -11,11 +9,9 @@ import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.graphql.types.ChapterMetaType
|
||||
import suwayomi.tachidesk.graphql.types.ChapterType
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrNull
|
||||
import suwayomi.tachidesk.manga.impl.chapter.getChapterDownloadReadyById
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.PageTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -203,43 +199,15 @@ class ChapterMutation {
|
||||
): CompletableFuture<FetchChapterPagesPayload> {
|
||||
val (clientMutationId, chapterId) = input
|
||||
|
||||
val chapter = transaction { ChapterTable.select { ChapterTable.id eq chapterId }.first() }
|
||||
val manga = transaction { MangaTable.select { MangaTable.id eq chapter[ChapterTable.manga] }.first() }
|
||||
val source = getCatalogueSourceOrNull(manga[MangaTable.sourceReference])!!
|
||||
|
||||
return future {
|
||||
source.getPageList(
|
||||
SChapter.create().apply {
|
||||
url = chapter[ChapterTable.url]
|
||||
name = chapter[ChapterTable.name]
|
||||
}
|
||||
)
|
||||
}.thenApply { pageList ->
|
||||
transaction {
|
||||
PageTable.deleteWhere { PageTable.chapter eq chapterId }
|
||||
PageTable.batchInsert(pageList) { page ->
|
||||
this[PageTable.index] = page.index
|
||||
this[PageTable.url] = page.url
|
||||
this[PageTable.imageUrl] = page.imageUrl
|
||||
this[PageTable.chapter] = chapterId
|
||||
}
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
val pageCount = pageList.size
|
||||
it[ChapterTable.pageCount] = pageCount
|
||||
it[ChapterTable.lastPageRead] = chapter[ChapterTable.lastPageRead].coerceAtMost(pageCount - 1)
|
||||
}
|
||||
}
|
||||
|
||||
val mangaId = manga[MangaTable.id].value
|
||||
val chapterIndex = chapter[ChapterTable.sourceOrder]
|
||||
getChapterDownloadReadyById(chapterId)
|
||||
}.thenApply { chapter ->
|
||||
FetchChapterPagesPayload(
|
||||
clientMutationId = clientMutationId,
|
||||
pages = List(pageList.size) { index ->
|
||||
"/api/v1/manga/$mangaId/chapter/$chapterIndex/page/$index"
|
||||
pages = List(chapter.pageCount) { index ->
|
||||
"/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}/page/$index"
|
||||
},
|
||||
chapter = ChapterType(
|
||||
transaction { ChapterTable.select { ChapterTable.id eq chapterId }.first() }
|
||||
)
|
||||
chapter = ChapterType(chapter)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user