migrate to Javalin 4

This commit is contained in:
Aria Moradi
2021-09-14 03:23:00 +04:30
parent 4f364e134b
commit 0173d5e4b3
11 changed files with 118 additions and 113 deletions

View File

@@ -5,7 +5,7 @@ import suwayomi.tachidesk.manga.impl.backup.BackupFlags
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupExport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator
import suwayomi.tachidesk.server.JavalinSetup
import suwayomi.tachidesk.server.JavalinSetup.future
import java.text.SimpleDateFormat
import java.util.Date
@@ -20,8 +20,8 @@ object BackupController {
/** expects a Tachiyomi protobuf backup in the body */
fun protobufImport(ctx: Context) {
ctx.json(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupImport.performRestore(ctx.bodyAsInputStream())
}
)
@@ -30,8 +30,8 @@ object BackupController {
/** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
fun protobufImportFile(ctx: Context) {
// TODO: rewrite this with ctx.uploadedFiles(), don't call the multipart field "backup.proto.gz"
ctx.json(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupImport.performRestore(ctx.uploadedFile("backup.proto.gz")!!.content)
}
)
@@ -40,8 +40,8 @@ object BackupController {
/** returns a Tachiyomi protobuf backup created from the current database as a body */
fun protobufExport(ctx: Context) {
ctx.contentType("application/octet-stream")
ctx.result(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
@@ -61,8 +61,8 @@ object BackupController {
val currentDate = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date())
ctx.header("Content-Disposition", """attachment; filename="tachidesk_$currentDate.proto.gz"""")
ctx.result(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
@@ -78,8 +78,8 @@ object BackupController {
/** Reports missing sources and trackers, expects a Tachiyomi protobuf backup in the body */
fun protobufValidate(ctx: Context) {
ctx.json(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupValidator.validate(ctx.bodyAsInputStream())
}
)
@@ -87,8 +87,8 @@ object BackupController {
/** Reports missing sources and trackers, expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
fun protobufValidateFile(ctx: Context) {
ctx.json(
JavalinSetup.future {
ctx.future(
future {
ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content)
}
)

View File

@@ -8,12 +8,12 @@ package suwayomi.tachidesk.manga.controller
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import io.javalin.http.Context
import io.javalin.websocket.WsHandler
import io.javalin.websocket.WsConfig
import suwayomi.tachidesk.manga.impl.download.DownloadManager
object DownloadController {
/** Download queue stats */
fun downloadsWS(ws: WsHandler) {
fun downloadsWS(ws: WsConfig) {
ws.onConnect { ctx ->
DownloadManager.addClient(ctx)
DownloadManager.notifyClient(ctx)

View File

@@ -18,7 +18,7 @@ object ExtensionController {
/** list all extensions */
fun list(ctx: Context) {
ctx.json(
ctx.future(
future {
ExtensionsList.getExtensionList()
}
@@ -29,7 +29,7 @@ object ExtensionController {
fun install(ctx: Context) {
val pkgName = ctx.pathParam("pkgName")
ctx.json(
ctx.future(
future {
Extension.installExtension(pkgName)
}
@@ -42,7 +42,7 @@ object ExtensionController {
val uploadedFile = ctx.uploadedFile("file")!!
logger.debug { "Uploaded extension file name: " + uploadedFile.filename }
ctx.json(
ctx.future(
future {
Extension.installExternalExtension(uploadedFile.content, uploadedFile.filename)
}
@@ -53,7 +53,7 @@ object ExtensionController {
fun update(ctx: Context) {
val pkgName = ctx.pathParam("pkgName")
ctx.json(
ctx.future(
future {
Extension.updateExtension(pkgName)
}
@@ -72,7 +72,7 @@ object ExtensionController {
fun icon(ctx: Context) {
val apkName = ctx.pathParam("apkName")
ctx.result(
ctx.future(
future { Extension.getExtensionIcon(apkName) }
.thenApply {
ctx.header("content-type", it.second)

View File

@@ -19,9 +19,9 @@ object MangaController {
/** get manga info */
fun retrieve(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt()
val onlineFetch = ctx.queryParam("onlineFetch", "false").toBoolean()
val onlineFetch = ctx.queryParam("onlineFetch")?.toBoolean() ?: false
ctx.json(
ctx.future(
future {
Manga.getManga(mangaId, onlineFetch)
}
@@ -32,7 +32,7 @@ object MangaController {
fun thumbnail(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result(
ctx.future(
future { Manga.getMangaThumbnail(mangaId) }
.thenApply {
ctx.header("content-type", it.second)
@@ -45,7 +45,7 @@ object MangaController {
fun addToLibrary(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result(
ctx.future(
future { Library.addMangaToLibrary(mangaId) }
)
}
@@ -54,7 +54,7 @@ object MangaController {
fun removeFromLibrary(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result(
ctx.future(
future { Library.removeMangaFromLibrary(mangaId) }
)
}
@@ -97,16 +97,16 @@ object MangaController {
fun chapterList(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt()
val onlineFetch = ctx.queryParam("onlineFetch", "false").toBoolean()
val onlineFetch = ctx.queryParam("onlineFetch")?.toBoolean() ?: false
ctx.json(future { Chapter.getChapterList(mangaId, onlineFetch) })
ctx.future(future { Chapter.getChapterList(mangaId, onlineFetch) })
}
/** used to display a chapter, get a chapter in order to show its pages */
fun chapterRetrieve(ctx: Context) {
val chapterIndex = ctx.pathParam("chapterIndex").toInt()
val mangaId = ctx.pathParam("mangaId").toInt()
ctx.json(future { Chapter.getChapter(chapterIndex, mangaId) })
ctx.future(future { Chapter.getChapter(chapterIndex, mangaId) })
}
/** used to modify a chapter's parameters */
@@ -143,7 +143,7 @@ object MangaController {
val chapterIndex = ctx.pathParam("chapterIndex").toInt()
val index = ctx.pathParam("index").toInt()
ctx.result(
ctx.future(
future { Page.getPageImage(mangaId, chapterIndex, index) }
.thenApply {
ctx.header("content-type", it.second)

View File

@@ -30,7 +30,7 @@ object SourceController {
fun popular(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json(
ctx.future(
future {
MangaList.getMangaList(sourceId, pageNum, popular = true)
}
@@ -41,7 +41,7 @@ object SourceController {
fun latest(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json(
ctx.future(
future {
MangaList.getMangaList(sourceId, pageNum, popular = false)
}
@@ -64,7 +64,7 @@ object SourceController {
/** fetch filters of source with id `sourceId` */
fun filters(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong()
val reset = ctx.queryParam("reset", "false").toBoolean()
val reset = ctx.queryParam("reset")?.toBoolean() ?: false
ctx.json(Search.getInitialFilterList(sourceId, reset))
}
@@ -74,7 +74,7 @@ object SourceController {
val sourceId = ctx.pathParam("sourceId").toLong()
val searchTerm = ctx.pathParam("searchTerm")
val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json(future { Search.sourceSearch(sourceId, searchTerm, pageNum) })
ctx.future(future { Search.sourceSearch(sourceId, searchTerm, pageNum) })
}
/** all source search */