mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-10 06:14:35 -05:00
Downloader Queries and Mutations (#610)
* Add downloader GraphQL endpoints * Fix names * DeleteDownloadedChapter(s) * DequeueChapterDownload(s)
This commit is contained in:
@@ -393,21 +393,7 @@ object Chapter {
|
||||
|
||||
private fun deleteChapters(input: MangaChapterBatchEditInput, mangaId: Int? = null) {
|
||||
if (input.chapterIds != null) {
|
||||
val chapterIds = input.chapterIds
|
||||
|
||||
transaction {
|
||||
ChapterTable.slice(ChapterTable.manga, ChapterTable.id)
|
||||
.select { ChapterTable.id inList chapterIds }
|
||||
.forEach { row ->
|
||||
val chapterMangaId = row[ChapterTable.manga].value
|
||||
val chapterId = row[ChapterTable.id].value
|
||||
ChapterDownloadHelper.delete(chapterMangaId, chapterId)
|
||||
}
|
||||
|
||||
ChapterTable.update({ ChapterTable.id inList chapterIds }) {
|
||||
it[isDownloaded] = false
|
||||
}
|
||||
}
|
||||
deleteChapters(input.chapterIds)
|
||||
} else if (input.chapterIndexes != null && mangaId != null) {
|
||||
transaction {
|
||||
val chapterIds = ChapterTable.slice(ChapterTable.manga, ChapterTable.id)
|
||||
@@ -426,6 +412,22 @@ object Chapter {
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteChapters(chapterIds: List<Int>) {
|
||||
transaction {
|
||||
ChapterTable.slice(ChapterTable.manga, ChapterTable.id)
|
||||
.select { ChapterTable.id inList chapterIds }
|
||||
.forEach { row ->
|
||||
val chapterMangaId = row[ChapterTable.manga].value
|
||||
val chapterId = row[ChapterTable.id].value
|
||||
ChapterDownloadHelper.delete(chapterMangaId, chapterId)
|
||||
}
|
||||
|
||||
ChapterTable.update({ ChapterTable.id inList chapterIds }) {
|
||||
it[isDownloaded] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getRecentChapters(pageNum: Int): PaginatedList<MangaChapterDataClass> {
|
||||
return paginatedFrom(pageNum) {
|
||||
transaction {
|
||||
|
||||
@@ -19,14 +19,16 @@ import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.Serializable
|
||||
import mu.KotlinLogging
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.subscriptions.downloadSubscriptionSource
|
||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
|
||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadState.Downloading
|
||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadState.Error
|
||||
@@ -108,6 +110,12 @@ object DownloadManager {
|
||||
|
||||
private val notifyFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
|
||||
val status = notifyFlow.sample(1.seconds)
|
||||
.map {
|
||||
getStatus()
|
||||
}
|
||||
.stateIn(scope, SharingStarted.Eagerly, getStatus())
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
notifyFlow.sample(1.seconds).collect {
|
||||
@@ -268,7 +276,6 @@ object DownloadManager {
|
||||
)
|
||||
downloadQueue.add(newDownloadChapter)
|
||||
saveDownloadQueue()
|
||||
downloadSubscriptionSource.publish(newDownloadChapter)
|
||||
logger.debug { "Added chapter ${chapter.id} to download queue ($newDownloadChapter)" }
|
||||
return newDownloadChapter
|
||||
}
|
||||
@@ -317,6 +324,15 @@ object DownloadManager {
|
||||
saveDownloadQueue()
|
||||
}
|
||||
|
||||
fun reorder(chapterId: Int, to: Int) {
|
||||
require(to >= 0) { "'to' must be over or equal to 0" }
|
||||
val download = downloadQueue.find { it.chapter.id == chapterId }
|
||||
?: return
|
||||
downloadQueue -= download
|
||||
downloadQueue.add(to, download)
|
||||
saveDownloadQueue()
|
||||
}
|
||||
|
||||
fun start() {
|
||||
logger.debug { "start" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user