mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-05 03:44:36 -05:00
refactor endpoints to the new styles
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package suwayomi.tachidesk.manga.controller
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.websocket.WsHandler
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadManager
|
||||
|
||||
object DownloadController {
|
||||
/** Download queue stats */
|
||||
fun downloadsWS(ws: WsHandler) {
|
||||
ws.onConnect { ctx ->
|
||||
DownloadManager.addClient(ctx)
|
||||
DownloadManager.notifyClient(ctx)
|
||||
}
|
||||
ws.onMessage { ctx ->
|
||||
DownloadManager.handleRequest(ctx)
|
||||
}
|
||||
ws.onClose { ctx ->
|
||||
DownloadManager.removeClient(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/** Start the downloader */
|
||||
fun start(ctx: Context) {
|
||||
DownloadManager.start()
|
||||
|
||||
ctx.status(200)
|
||||
}
|
||||
|
||||
/** Stop the downloader */
|
||||
fun stop(ctx: Context) {
|
||||
DownloadManager.stop()
|
||||
|
||||
ctx.status(200)
|
||||
}
|
||||
|
||||
/** clear download queue */
|
||||
fun clear(ctx: Context) {
|
||||
DownloadManager.clear()
|
||||
|
||||
ctx.status(200)
|
||||
}
|
||||
|
||||
/** Queue chapter for download */
|
||||
fun queueChapter(ctx: Context) {
|
||||
val chapterIndex = ctx.pathParam("chapterIndex").toInt()
|
||||
val mangaId = ctx.pathParam("mangaId").toInt()
|
||||
|
||||
DownloadManager.enqueue(chapterIndex, mangaId)
|
||||
|
||||
ctx.status(200)
|
||||
}
|
||||
|
||||
/** delete chapter from download queue */
|
||||
fun unqueueChapter(ctx: Context) {
|
||||
val chapterIndex = ctx.pathParam("chapterIndex").toInt()
|
||||
val mangaId = ctx.pathParam("mangaId").toInt()
|
||||
|
||||
DownloadManager.unqueue(chapterIndex, mangaId)
|
||||
|
||||
ctx.status(200)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user