From d6127d6811716a759c6ef951a14bb4b4da7a0750 Mon Sep 17 00:00:00 2001 From: Valter Martinek Date: Wed, 16 Nov 2022 17:31:48 +0100 Subject: [PATCH] Add batch endpoint for removing downloads from download queue (#452) --- .../suwayomi/tachidesk/manga/MangaAPI.kt | 1 + .../manga/controller/DownloadController.kt | 22 +++++++++++++++++++ .../manga/impl/download/DownloadManager.kt | 8 +++++++ 3 files changed, 31 insertions(+) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt index 5736f7fd9..56bb0d9c1 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt @@ -122,6 +122,7 @@ object MangaAPI { delete("{mangaId}/chapter/{chapterIndex}", DownloadController.unqueueChapter) patch("{mangaId}/chapter/{chapterIndex}/reorder/{to}", DownloadController.reorderChapter) post("batch", DownloadController.queueChapters) + delete("batch", DownloadController.unqueueChapters) } path("update") { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/DownloadController.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/DownloadController.kt index 7d7f95474..e501a720d 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/DownloadController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/DownloadController.kt @@ -134,6 +134,28 @@ object DownloadController { } ) + /** delete multiple chapters from download queue */ + val unqueueChapters = handler( + documentWith = { + withOperation { + summary("Downloader remove multiple downloads") + description("Remove multiple chapters downloads from queue") + } + body() + }, + behaviorOf = { ctx -> + val input = json.decodeFromString(ctx.body()) + ctx.future( + future { + DownloadManager.unqueue(input) + } + ) + }, + withResults = { + httpCode(HttpCode.OK) + } + ) + /** delete chapter from download queue */ val unqueueChapter = handler( pathParam("chapterIndex"), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt index d5c936931..f85c85f7a 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt @@ -190,6 +190,14 @@ object DownloadManager { addMultipleToQueue(inputPairs) } + fun unqueue(input: EnqueueInput) { + if (input.chapterIds.isNullOrEmpty()) return + + downloadQueue.removeIf { it.chapter.id in input.chapterIds } + + notifyAllClients() + } + /** * Tries to add multiple inputs to queue * If any of inputs was actually added to queue, starts the queue