Skip to content

Commit

Permalink
Add batch endpoint for removing downloads from download queue (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinek authored Nov 16, 2022
1 parent 67e09e2 commit d6127d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnqueueInput>()
},
behaviorOf = { ctx ->
val input = json.decodeFromString<EnqueueInput>(ctx.body())
ctx.future(
future {
DownloadManager.unqueue(input)
}
)
},
withResults = {
httpCode(HttpCode.OK)
}
)

/** delete chapter from download queue */
val unqueueChapter = handler(
pathParam<Int>("chapterIndex"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6127d6

Please sign in to comment.