mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
document all endpoints (#350)
* Document all endpoints * Forgot about global endpoints
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package suwayomi.tachidesk.manga.controller
|
||||
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpCode
|
||||
import io.javalin.websocket.WsConfig
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@@ -12,10 +11,15 @@ import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
import suwayomi.tachidesk.manga.impl.update.IUpdater
|
||||
import suwayomi.tachidesk.manga.impl.update.UpdateStatus
|
||||
import suwayomi.tachidesk.manga.impl.update.UpdaterSocket
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PaginatedList
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import suwayomi.tachidesk.server.util.formParam
|
||||
import suwayomi.tachidesk.server.util.handler
|
||||
import suwayomi.tachidesk.server.util.pathParam
|
||||
import suwayomi.tachidesk.server.util.withOperation
|
||||
|
||||
/*
|
||||
@@ -29,35 +33,57 @@ object UpdateController {
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
/** get recently updated manga chapters */
|
||||
fun recentChapters(ctx: Context) {
|
||||
val pageNum = ctx.pathParam("pageNum").toInt()
|
||||
|
||||
ctx.future(
|
||||
future {
|
||||
Chapter.getRecentChapters(pageNum)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun categoryUpdate(ctx: Context) {
|
||||
val categoryId = ctx.formParam("category")?.toIntOrNull()
|
||||
val categoriesForUpdate = ArrayList<CategoryDataClass>()
|
||||
if (categoryId == null) {
|
||||
logger.info { "Adding Library to Update Queue" }
|
||||
categoriesForUpdate.addAll(Category.getCategoryList())
|
||||
} else {
|
||||
val category = Category.getCategoryById(categoryId)
|
||||
if (category != null) {
|
||||
categoriesForUpdate.add(category)
|
||||
} else {
|
||||
logger.info { "No Category found" }
|
||||
ctx.status(HttpCode.BAD_REQUEST)
|
||||
return
|
||||
val recentChapters = handler(
|
||||
pathParam<Int>("pageNum"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Updates fetch")
|
||||
description("Get recently updated manga chapters")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, pageNum ->
|
||||
ctx.future(
|
||||
future {
|
||||
Chapter.getRecentChapters(pageNum)
|
||||
}
|
||||
)
|
||||
},
|
||||
withResults = {
|
||||
json<PaginatedList<MangaDataClass>>(HttpCode.OK)
|
||||
}
|
||||
addCategoriesToUpdateQueue(categoriesForUpdate, true)
|
||||
ctx.status(HttpCode.OK)
|
||||
}
|
||||
)
|
||||
|
||||
val categoryUpdate = handler(
|
||||
formParam<Int?>("categoryId"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Updater start")
|
||||
description("Starts the updater")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, categoryId ->
|
||||
val categoriesForUpdate = ArrayList<CategoryDataClass>()
|
||||
if (categoryId == null) {
|
||||
logger.info { "Adding Library to Update Queue" }
|
||||
categoriesForUpdate.addAll(Category.getCategoryList())
|
||||
} else {
|
||||
val category = Category.getCategoryById(categoryId)
|
||||
if (category != null) {
|
||||
categoriesForUpdate.add(category)
|
||||
} else {
|
||||
logger.info { "No Category found" }
|
||||
ctx.status(HttpCode.BAD_REQUEST)
|
||||
return@handler
|
||||
}
|
||||
}
|
||||
addCategoriesToUpdateQueue(categoriesForUpdate, true)
|
||||
ctx.status(HttpCode.OK)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpCode.OK)
|
||||
httpCode(HttpCode.BAD_REQUEST)
|
||||
}
|
||||
)
|
||||
|
||||
private fun addCategoriesToUpdateQueue(categories: List<CategoryDataClass>, clear: Boolean = false) {
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
@@ -84,15 +110,27 @@ object UpdateController {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSummary(ctx: Context) {
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
ctx.json(updater.getStatus().value.getJsonSummary())
|
||||
}
|
||||
val updateSummary = handler(
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Updater summary")
|
||||
description("Gets the latest updater summary")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx ->
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
ctx.json(updater.getStatus().value.getJsonSummary())
|
||||
},
|
||||
withResults = {
|
||||
json<UpdateStatus>(HttpCode.OK)
|
||||
}
|
||||
)
|
||||
|
||||
val reset = handler(
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Stops and resets the Updater")
|
||||
summary("Updater reset")
|
||||
description("Stops and resets the Updater")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx ->
|
||||
|
||||
Reference in New Issue
Block a user