mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-11 23:04:33 -05:00
add batch download api (#436)
* Add POST /downloads endpoint for creating multiple * Fix review notes * Add chapter id to API endpoints * Rewrite batch chapter download to use chapter id instead of mangaId+chapterIndex combination * Change EnqueueInput format to be more futureproof * Change endpoint path * Change endpoint path
This commit is contained in:
@@ -9,13 +9,21 @@ package suwayomi.tachidesk.manga.controller
|
||||
|
||||
import io.javalin.http.HttpCode
|
||||
import io.javalin.websocket.WsConfig
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.conf.global
|
||||
import org.kodein.di.instance
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadManager
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadManager.EnqueueInput
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import suwayomi.tachidesk.server.util.handler
|
||||
import suwayomi.tachidesk.server.util.pathParam
|
||||
import suwayomi.tachidesk.server.util.withOperation
|
||||
|
||||
object DownloadController {
|
||||
private val json by DI.global.instance<Json>()
|
||||
|
||||
/** Download queue stats */
|
||||
fun downloadsWS(ws: WsConfig) {
|
||||
ws.onConnect { ctx ->
|
||||
@@ -84,20 +92,20 @@ object DownloadController {
|
||||
}
|
||||
)
|
||||
|
||||
/** Queue chapter for download */
|
||||
/** Queue single chapter for download */
|
||||
val queueChapter = handler(
|
||||
pathParam<Int>("chapterIndex"),
|
||||
pathParam<Int>("mangaId"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Downloader add chapter")
|
||||
description("Queue chapter for download")
|
||||
summary("Downloader add single chapter")
|
||||
description("Queue single chapter for download")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, chapterIndex, mangaId ->
|
||||
ctx.future(
|
||||
future {
|
||||
DownloadManager.enqueue(chapterIndex, mangaId)
|
||||
DownloadManager.enqueueWithChapterIndex(mangaId, chapterIndex)
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -107,6 +115,27 @@ object DownloadController {
|
||||
}
|
||||
)
|
||||
|
||||
val queueChapters = handler(
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Downloader add multiple chapters")
|
||||
description("Queue multiple chapters for download")
|
||||
}
|
||||
body<EnqueueInput>()
|
||||
},
|
||||
behaviorOf = { ctx ->
|
||||
val inputs = json.decodeFromString<EnqueueInput>(ctx.body())
|
||||
ctx.future(
|
||||
future {
|
||||
DownloadManager.enqueue(inputs)
|
||||
}
|
||||
)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpCode.OK)
|
||||
}
|
||||
)
|
||||
|
||||
/** delete chapter from download queue */
|
||||
val unqueueChapter = handler(
|
||||
pathParam<Int>("chapterIndex"),
|
||||
|
||||
Reference in New Issue
Block a user