Feature/auto download ahead (#681)

* Add "download ahead" mutation

Checks if the specified number of unread chapters, that should be downloaded, are available.
In case not enough chapters are downloaded, the number of missing unread chapters will get downloaded

* Optionally pass the latest read chapter id of a manga

In case a chapter will get marked as read, which also triggered the download ahead call, it's possible, that by the time the download ahead logic gets triggered, the chapter hasn't been marked as read yet.
This could then cause this chapter to be included in the chapters to get downloaded.
By providing the chapter id, this chapter will be used as the latest read chapter instead, and thus, not be included inn the chapters to download.
This commit is contained in:
schroda
2023-10-05 04:02:10 +02:00
committed by GitHub
parent c8865ad185
commit ef0a6f54b8
3 changed files with 113 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.ChapterType
import suwayomi.tachidesk.graphql.types.DownloadStatus
import suwayomi.tachidesk.manga.impl.Chapter
import suwayomi.tachidesk.manga.impl.Manga
import suwayomi.tachidesk.manga.impl.download.DownloadManager
import suwayomi.tachidesk.manga.impl.download.model.Status
import suwayomi.tachidesk.manga.model.table.ChapterTable
@@ -257,4 +258,20 @@ class DownloadMutation {
)
}
}
data class DownloadAheadInput(
val clientMutationId: String? = null,
val mangaIds: List<Int> = emptyList(),
val latestReadChapterIds: List<Int>? = null
)
data class DownloadAheadPayload(val clientMutationId: String?)
fun downloadAhead(input: DownloadAheadInput): DownloadAheadPayload {
val (clientMutationId, mangaIds, latestReadChapterIds) = input
Manga.downloadAhead(mangaIds, latestReadChapterIds ?: emptyList())
return DownloadAheadPayload(clientMutationId)
}
}