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
+1 -1
View File
@@ -89,6 +89,6 @@ configure(projects) {
// dependency both in AndroidCompat and server, version locked by javalin // dependency both in AndroidCompat and server, version locked by javalin
implementation("com.fasterxml.jackson.core:jackson-annotations:2.10.3") implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4")
} }
} }
+3 -3
View File
@@ -31,10 +31,10 @@ dependencies {
implementation("com.squareup.okio:okio:2.10.0") implementation("com.squareup.okio:okio:2.10.0")
// Javalin api // Javalin api
implementation("io.javalin:javalin:3.13.11") implementation("io.javalin:javalin:4.0.0")
// jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency` // jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency`
implementation("com.fasterxml.jackson.core:jackson-databind:2.10.3") implementation("com.fasterxml.jackson.core:jackson-databind:2.12.4")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.10.3") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.4")
// Exposed ORM // Exposed ORM
val exposedVersion = "0.34.1" val exposedVersion = "0.34.1"
@@ -28,7 +28,7 @@ object AnimeAPI {
fun defineEndpoints(app: Javalin) { fun defineEndpoints(app: Javalin) {
// list all extensions // list all extensions
app.get("/api/v1/anime/extension/list") { ctx -> app.get("/api/v1/anime/extension/list") { ctx ->
ctx.json( ctx.future(
future { future {
getExtensionList() getExtensionList()
} }
@@ -36,10 +36,10 @@ object AnimeAPI {
} }
// install extension identified with "pkgName" // install extension identified with "pkgName"
app.get("/api/v1/anime/extension/install/:pkgName") { ctx -> app.get("/api/v1/anime/extension/install/{pkgName}") { ctx ->
val pkgName = ctx.pathParam("pkgName") val pkgName = ctx.pathParam("pkgName")
ctx.json( ctx.future(
future { future {
installExtension(pkgName) installExtension(pkgName)
} }
@@ -47,10 +47,10 @@ object AnimeAPI {
} }
// update extension identified with "pkgName" // update extension identified with "pkgName"
app.get("/api/v1/anime/extension/update/:pkgName") { ctx -> app.get("/api/v1/anime/extension/update/{pkgName}") { ctx ->
val pkgName = ctx.pathParam("pkgName") val pkgName = ctx.pathParam("pkgName")
ctx.json( ctx.future(
future { future {
updateExtension(pkgName) updateExtension(pkgName)
} }
@@ -58,7 +58,7 @@ object AnimeAPI {
} }
// uninstall extension identified with "pkgName" // uninstall extension identified with "pkgName"
app.get("/api/v1/anime/extension/uninstall/:pkgName") { ctx -> app.get("/api/v1/anime/extension/uninstall/{pkgName}") { ctx ->
val pkgName = ctx.pathParam("pkgName") val pkgName = ctx.pathParam("pkgName")
uninstallExtension(pkgName) uninstallExtension(pkgName)
@@ -66,10 +66,10 @@ object AnimeAPI {
} }
// icon for extension named `apkName` // icon for extension named `apkName`
app.get("/api/v1/anime/extension/icon/:apkName") { ctx -> // TODO: move to pkgName app.get("/api/v1/anime/extension/icon/{apkName}") { ctx -> // TODO: move to pkgName
val apkName = ctx.pathParam("apkName") val apkName = ctx.pathParam("apkName")
ctx.result( ctx.future(
future { getExtensionIcon(apkName) } future { getExtensionIcon(apkName) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
@@ -84,16 +84,16 @@ object AnimeAPI {
} }
// fetch source with id `sourceId` // fetch source with id `sourceId`
app.get("/api/v1/anime/source/:sourceId") { ctx -> app.get("/api/v1/anime/source/{sourceId}") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
ctx.json(getAnimeSource(sourceId)) ctx.json(getAnimeSource(sourceId))
} }
// popular animes from source with id `sourceId` // popular animes from source with id `sourceId`
app.get("/api/v1/anime/source/:sourceId/popular/:pageNum") { ctx -> app.get("/api/v1/anime/source/{sourceId}/popular/{pageNum}") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt() val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json( ctx.future(
future { future {
getAnimeList(sourceId, pageNum, popular = true) getAnimeList(sourceId, pageNum, popular = true)
} }
@@ -101,10 +101,10 @@ object AnimeAPI {
} }
// latest animes from source with id `sourceId` // latest animes from source with id `sourceId`
app.get("/api/v1/anime/source/:sourceId/latest/:pageNum") { ctx -> app.get("/api/v1/anime/source/{sourceId}/latest/{pageNum}") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt() val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json( ctx.future(
future { future {
getAnimeList(sourceId, pageNum, popular = false) getAnimeList(sourceId, pageNum, popular = false)
} }
@@ -112,11 +112,11 @@ object AnimeAPI {
} }
// get anime info // get anime info
app.get("/api/v1/anime/anime/:animeId/") { ctx -> app.get("/api/v1/anime/anime/{animeId}/") { ctx ->
val animeId = ctx.pathParam("animeId").toInt() val animeId = ctx.pathParam("animeId").toInt()
val onlineFetch = ctx.queryParam("onlineFetch", "false").toBoolean() val onlineFetch = ctx.queryParam("onlineFetch")?.toBoolean() ?: false
ctx.json( ctx.future(
future { future {
getAnime(animeId, onlineFetch) getAnime(animeId, onlineFetch)
} }
@@ -124,10 +124,10 @@ object AnimeAPI {
} }
// anime thumbnail // anime thumbnail
app.get("api/v1/anime/anime/:animeId/thumbnail") { ctx -> app.get("api/v1/anime/anime/{animeId}/thumbnail") { ctx ->
val animeId = ctx.pathParam("animeId").toInt() val animeId = ctx.pathParam("animeId").toInt()
ctx.result( ctx.future(
future { getAnimeThumbnail(animeId) } future { getAnimeThumbnail(animeId) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
@@ -137,13 +137,13 @@ object AnimeAPI {
} }
// //
// // list manga's categories // // list manga's categories
// app.get("api/v1/manga/:mangaId/category/") { ctx -> // app.get("api/v1/manga/{mangaId}/category/") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// ctx.json(getMangaCategories(mangaId)) // ctx.json(getMangaCategories(mangaId))
// } // }
// //
// // adds the manga to category // // adds the manga to category
// app.get("api/v1/manga/:mangaId/category/:categoryId") { ctx -> // app.get("api/v1/manga/{mangaId}/category/{categoryId}") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// addMangaToCategory(mangaId, categoryId) // addMangaToCategory(mangaId, categoryId)
@@ -151,7 +151,7 @@ object AnimeAPI {
// } // }
// //
// // removes the manga from the category // // removes the manga from the category
// app.delete("api/v1/manga/:mangaId/category/:categoryId") { ctx -> // app.delete("api/v1/manga/{mangaId}/category/{categoryId}") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// removeMangaFromCategory(mangaId, categoryId) // removeMangaFromCategory(mangaId, categoryId)
@@ -159,23 +159,23 @@ object AnimeAPI {
// } // }
// //
// get episode list when showing a anime // get episode list when showing a anime
app.get("/api/v1/anime/anime/:animeId/episodes") { ctx -> app.get("/api/v1/anime/anime/{animeId}/episodes") { ctx ->
val animeId = ctx.pathParam("animeId").toInt() val animeId = ctx.pathParam("animeId").toInt()
val onlineFetch = ctx.queryParam("onlineFetch")?.toBoolean() val onlineFetch = ctx.queryParam("onlineFetch")?.toBoolean()
ctx.json(future { getEpisodeList(animeId, onlineFetch) }) ctx.future(future { getEpisodeList(animeId, onlineFetch) })
} }
// used to display a episode, get a episode in order to show it's <Quality pending> // used to display a episode, get a episode in order to show it's <Quality pending>
app.get("/api/v1/anime/anime/:animeId/episode/:episodeIndex") { ctx -> app.get("/api/v1/anime/anime/{animeId}/episode/{episodeIndex}") { ctx ->
val episodeIndex = ctx.pathParam("episodeIndex").toInt() val episodeIndex = ctx.pathParam("episodeIndex").toInt()
val animeId = ctx.pathParam("animeId").toInt() val animeId = ctx.pathParam("animeId").toInt()
ctx.json(future { getEpisode(episodeIndex, animeId) }) ctx.future(future { getEpisode(episodeIndex, animeId) })
} }
// used to modify a episode's parameters // used to modify a episode's parameters
app.patch("/api/v1/anime/anime/:animeId/episode/:episodeIndex") { ctx -> app.patch("/api/v1/anime/anime/{animeId}/episode/{episodeIndex}") { ctx ->
val episodeIndex = ctx.pathParam("episodeIndex").toInt() val episodeIndex = ctx.pathParam("episodeIndex").toInt()
val animeId = ctx.pathParam("animeId").toInt() val animeId = ctx.pathParam("animeId").toInt()
@@ -190,7 +190,7 @@ object AnimeAPI {
} }
// //
// // get page at index "index" // // get page at index "index"
// app.get("/api/v1/manga/:mangaId/chapter/:chapterIndex/page/:index") { ctx -> // app.get("/api/v1/manga/{mangaId}/chapter/{chapterIndex}/page/{index}") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// val chapterIndex = ctx.pathParam("chapterIndex").toInt() // val chapterIndex = ctx.pathParam("chapterIndex").toInt()
// val index = ctx.pathParam("index").toInt() // val index = ctx.pathParam("index").toInt()
@@ -205,49 +205,49 @@ object AnimeAPI {
// } // }
// //
// // submit a chapter for download // // submit a chapter for download
// app.put("/api/v1/manga/:mangaId/chapter/:chapterIndex/download") { ctx -> // app.put("/api/v1/manga/{mangaId}/chapter/{chapterIndex}/download") { ctx ->
// // TODO // // TODO
// } // }
// //
// // cancel a chapter download // // cancel a chapter download
// app.delete("/api/v1/manga/:mangaId/chapter/:chapterIndex/download") { ctx -> // app.delete("/api/v1/manga/{mangaId}/chapter/{chapterIndex}/download") { ctx ->
// // TODO // // TODO
// } // }
// //
// // global search, Not implemented yet // // global search, Not implemented yet
// app.get("/api/v1/search/:searchTerm") { ctx -> // app.get("/api/v1/search/{searchTerm}") { ctx ->
// val searchTerm = ctx.pathParam("searchTerm") // val searchTerm = ctx.pathParam("searchTerm")
// ctx.json(sourceGlobalSearch(searchTerm)) // ctx.json(sourceGlobalSearch(searchTerm))
// } // }
// //
// single source search // single source search
app.get("/api/v1/anime/source/:sourceId/search/:searchTerm/:pageNum") { ctx -> app.get("/api/v1/anime/source/{sourceId}/search/{searchTerm}/{pageNum}") { ctx ->
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val searchTerm = ctx.pathParam("searchTerm") val searchTerm = ctx.pathParam("searchTerm")
val pageNum = ctx.pathParam("pageNum").toInt() val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json(future { sourceSearch(sourceId, searchTerm, pageNum) }) ctx.future(future { sourceSearch(sourceId, searchTerm, pageNum) })
} }
// //
// // source filter list // // source filter list
// app.get("/api/v1/source/:sourceId/filters/") { ctx -> // app.get("/api/v1/source/{sourceId}/filters/") { ctx ->
// val sourceId = ctx.pathParam("sourceId").toLong() // val sourceId = ctx.pathParam("sourceId").toLong()
// ctx.json(sourceFilters(sourceId)) // ctx.json(sourceFilters(sourceId))
// } // }
// //
// // adds the manga to library // // adds the manga to library
// app.get("api/v1/manga/:mangaId/library") { ctx -> // app.get("api/v1/manga/{mangaId}/library") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// //
// ctx.result( // ctx.future(
// JavalinSetup.future { addMangaToLibrary(mangaId) } // JavalinSetup.future { addMangaToLibrary(mangaId) }
// ) // )
// } // }
// //
// // removes the manga from the library // // removes the manga from the library
// app.delete("api/v1/manga/:mangaId/library") { ctx -> // app.delete("api/v1/manga/{mangaId}/library") { ctx ->
// val mangaId = ctx.pathParam("mangaId").toInt() // val mangaId = ctx.pathParam("mangaId").toInt()
// //
// ctx.result( // ctx.future(
// JavalinSetup.future { removeMangaFromLibrary(mangaId) } // JavalinSetup.future { removeMangaFromLibrary(mangaId) }
// ) // )
// } // }
@@ -275,7 +275,7 @@ object AnimeAPI {
// } // }
// //
// // category modification // // category modification
// app.patch("/api/v1/category/:categoryId") { ctx -> // app.patch("/api/v1/category/{categoryId}") { ctx ->
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// val name = ctx.formParam("name") // val name = ctx.formParam("name")
// val isDefault = ctx.formParam("default")?.toBoolean() // val isDefault = ctx.formParam("default")?.toBoolean()
@@ -284,7 +284,7 @@ object AnimeAPI {
// } // }
// //
// // category re-ordering // // category re-ordering
// app.patch("/api/v1/category/:categoryId/reorder") { ctx -> // app.patch("/api/v1/category/{categoryId}/reorder") { ctx ->
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// val from = ctx.formParam("from")!!.toInt() // val from = ctx.formParam("from")!!.toInt()
// val to = ctx.formParam("to")!!.toInt() // val to = ctx.formParam("to")!!.toInt()
@@ -293,21 +293,21 @@ object AnimeAPI {
// } // }
// //
// // category delete // // category delete
// app.delete("/api/v1/category/:categoryId") { ctx -> // app.delete("/api/v1/category/{categoryId}") { ctx ->
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// Category.removeCategory(categoryId) // Category.removeCategory(categoryId)
// ctx.status(200) // ctx.status(200)
// } // }
// //
// // returns the manga list associated with a category // // returns the manga list associated with a category
// app.get("/api/v1/category/:categoryId") { ctx -> // app.get("/api/v1/category/{categoryId}") { ctx ->
// val categoryId = ctx.pathParam("categoryId").toInt() // val categoryId = ctx.pathParam("categoryId").toInt()
// ctx.json(getCategoryMangaList(categoryId)) // ctx.json(getCategoryMangaList(categoryId))
// } // }
// //
// // expects a Tachiyomi legacy backup json in the body // // expects a Tachiyomi legacy backup json in the body
// app.post("/api/v1/backup/legacy/import") { ctx -> // app.post("/api/v1/backup/legacy/import") { ctx ->
// ctx.result( // ctx.future(
// future { // future {
// restoreLegacyBackup(ctx.bodyAsInputStream()) // restoreLegacyBackup(ctx.bodyAsInputStream())
// } // }
@@ -316,7 +316,7 @@ object AnimeAPI {
// //
// // expects a Tachiyomi legacy backup json as a file upload, the file must be named "backup.json" // // expects a Tachiyomi legacy backup json as a file upload, the file must be named "backup.json"
// app.post("/api/v1/backup/legacy/import/file") { ctx -> // app.post("/api/v1/backup/legacy/import/file") { ctx ->
// ctx.result( // ctx.future(
// JavalinSetup.future { // JavalinSetup.future {
// restoreLegacyBackup(ctx.uploadedFile("backup.json")!!.content) // restoreLegacyBackup(ctx.uploadedFile("backup.json")!!.content)
// } // }
@@ -326,7 +326,7 @@ object AnimeAPI {
// // returns a Tachiyomi legacy backup json created from the current database as a json body // // returns a Tachiyomi legacy backup json created from the current database as a json body
// app.get("/api/v1/backup/legacy/export") { ctx -> // app.get("/api/v1/backup/legacy/export") { ctx ->
// ctx.contentType("application/json") // ctx.contentType("application/json")
// ctx.result( // ctx.future(
// JavalinSetup.future { // JavalinSetup.future {
// createLegacyBackup( // createLegacyBackup(
// BackupFlags( // BackupFlags(
@@ -348,7 +348,7 @@ object AnimeAPI {
// val currentDate = sdf.format(Date()) // val currentDate = sdf.format(Date())
// //
// ctx.header("Content-Disposition", "attachment; filename=\"tachidesk_$currentDate.json\"") // ctx.header("Content-Disposition", "attachment; filename=\"tachidesk_$currentDate.json\"")
// ctx.result( // ctx.future(
// JavalinSetup.future { // JavalinSetup.future {
// createLegacyBackup( // createLegacyBackup(
// BackupFlags( // BackupFlags(
@@ -25,59 +25,59 @@ object MangaAPI {
path("extension") { path("extension") {
get("list", ExtensionController::list) get("list", ExtensionController::list)
get("install/:pkgName", ExtensionController::install) get("install/{pkgName}", ExtensionController::install)
post("install", ExtensionController::installFile) post("install", ExtensionController::installFile)
get("update/:pkgName", ExtensionController::update) get("update/{pkgName}", ExtensionController::update)
get("uninstall/:pkgName", ExtensionController::uninstall) get("uninstall/{pkgName}", ExtensionController::uninstall)
get("icon/:apkName", ExtensionController::icon) get("icon/{apkName}", ExtensionController::icon)
} }
path("source") { path("source") {
get("list", SourceController::list) get("list", SourceController::list)
get(":sourceId", SourceController::retrieve) get("{sourceId}", SourceController::retrieve)
get(":sourceId/popular/:pageNum", SourceController::popular) get("{sourceId}/popular/{pageNum}", SourceController::popular)
get(":sourceId/latest/:pageNum", SourceController::latest) get("{sourceId}/latest/{pageNum}", SourceController::latest)
get(":sourceId/preferences", SourceController::getPreferences) get("{sourceId}/preferences", SourceController::getPreferences)
post(":sourceId/preferences", SourceController::setPreference) post("{sourceId}/preferences", SourceController::setPreference)
get(":sourceId/filters", SourceController::filters) get("{sourceId}/filters", SourceController::filters)
get(":sourceId/search/:searchTerm/:pageNum", SourceController::searchSingle) get("{sourceId}/search/{searchTerm}/{pageNum}", SourceController::searchSingle)
// get("search/:searchTerm/:pageNum", SourceController::searchGlobal) // get("search/{searchTerm}/{pageNum}", SourceController::searchGlobal)
} }
path("manga") { path("manga") {
get(":mangaId", MangaController::retrieve) get("{mangaId}", MangaController::retrieve)
get(":mangaId/thumbnail", MangaController::thumbnail) get("{mangaId}/thumbnail", MangaController::thumbnail)
get(":mangaId/category", MangaController::categoryList) get("{mangaId}/category", MangaController::categoryList)
get(":mangaId/category/:categoryId", MangaController::addToCategory) get("{mangaId}/category/{categoryId}", MangaController::addToCategory)
delete(":mangaId/category/:categoryId", MangaController::removeFromCategory) delete("{mangaId}/category/{categoryId}", MangaController::removeFromCategory)
get(":mangaId/library", MangaController::addToLibrary) get("{mangaId}/library", MangaController::addToLibrary)
delete(":mangaId/library", MangaController::removeFromLibrary) delete("{mangaId}/library", MangaController::removeFromLibrary)
patch(":mangaId/meta", MangaController::meta) patch("{mangaId}/meta", MangaController::meta)
get(":mangaId/chapters", MangaController::chapterList) get("{mangaId}/chapters", MangaController::chapterList)
get(":mangaId/chapter/:chapterIndex", MangaController::chapterRetrieve) get("{mangaId}/chapter/{chapterIndex}", MangaController::chapterRetrieve)
patch(":mangaId/chapter/:chapterIndex", MangaController::chapterModify) patch("{mangaId}/chapter/{chapterIndex}", MangaController::chapterModify)
patch(":mangaId/chapter/:chapterIndex/meta", MangaController::chapterMeta) patch("{mangaId}/chapter/{chapterIndex}/meta", MangaController::chapterMeta)
get(":mangaId/chapter/:chapterIndex/page/:index", MangaController::pageRetrieve) get("{mangaId}/chapter/{chapterIndex}/page/{index}", MangaController::pageRetrieve)
} }
path("category") { path("category") {
get("", CategoryController::categoryList) get("", CategoryController::categoryList)
post("", CategoryController::categoryCreate) post("", CategoryController::categoryCreate)
get(":categoryId", CategoryController::categoryMangas) get("{categoryId}", CategoryController::categoryMangas)
patch(":categoryId", CategoryController::categoryModify) patch("{categoryId}", CategoryController::categoryModify)
delete(":categoryId", CategoryController::categoryDelete) delete("{categoryId}", CategoryController::categoryDelete)
patch("reorder", CategoryController::categoryReorder) patch("reorder", CategoryController::categoryReorder)
} }
@@ -102,8 +102,8 @@ object MangaAPI {
} }
path("download") { path("download") {
get(":mangaId/chapter/:chapterIndex", DownloadController::queueChapter) get("{mangaId}/chapter/{chapterIndex}", DownloadController::queueChapter)
delete(":mangaId/chapter/:chapterIndex", DownloadController::unqueueChapter) delete("{mangaId}/chapter/{chapterIndex}", DownloadController::unqueueChapter)
} }
} }
} }
@@ -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.ProtoBackupExport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator 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.text.SimpleDateFormat
import java.util.Date import java.util.Date
@@ -20,8 +20,8 @@ object BackupController {
/** expects a Tachiyomi protobuf backup in the body */ /** expects a Tachiyomi protobuf backup in the body */
fun protobufImport(ctx: Context) { fun protobufImport(ctx: Context) {
ctx.json( ctx.future(
JavalinSetup.future { future {
ProtoBackupImport.performRestore(ctx.bodyAsInputStream()) 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" */ /** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
fun protobufImportFile(ctx: Context) { fun protobufImportFile(ctx: Context) {
// TODO: rewrite this with ctx.uploadedFiles(), don't call the multipart field "backup.proto.gz" // TODO: rewrite this with ctx.uploadedFiles(), don't call the multipart field "backup.proto.gz"
ctx.json( ctx.future(
JavalinSetup.future { future {
ProtoBackupImport.performRestore(ctx.uploadedFile("backup.proto.gz")!!.content) 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 */ /** returns a Tachiyomi protobuf backup created from the current database as a body */
fun protobufExport(ctx: Context) { fun protobufExport(ctx: Context) {
ctx.contentType("application/octet-stream") ctx.contentType("application/octet-stream")
ctx.result( ctx.future(
JavalinSetup.future { future {
ProtoBackupExport.createBackup( ProtoBackupExport.createBackup(
BackupFlags( BackupFlags(
includeManga = true, includeManga = true,
@@ -61,8 +61,8 @@ object BackupController {
val currentDate = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date()) val currentDate = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date())
ctx.header("Content-Disposition", """attachment; filename="tachidesk_$currentDate.proto.gz"""") ctx.header("Content-Disposition", """attachment; filename="tachidesk_$currentDate.proto.gz"""")
ctx.result( ctx.future(
JavalinSetup.future { future {
ProtoBackupExport.createBackup( ProtoBackupExport.createBackup(
BackupFlags( BackupFlags(
includeManga = true, includeManga = true,
@@ -78,8 +78,8 @@ object BackupController {
/** Reports missing sources and trackers, expects a Tachiyomi protobuf backup in the body */ /** Reports missing sources and trackers, expects a Tachiyomi protobuf backup in the body */
fun protobufValidate(ctx: Context) { fun protobufValidate(ctx: Context) {
ctx.json( ctx.future(
JavalinSetup.future { future {
ProtoBackupValidator.validate(ctx.bodyAsInputStream()) 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" */ /** 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) { fun protobufValidateFile(ctx: Context) {
ctx.json( ctx.future(
JavalinSetup.future { future {
ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content) ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content)
} }
) )
@@ -8,12 +8,12 @@ package suwayomi.tachidesk.manga.controller
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import io.javalin.http.Context import io.javalin.http.Context
import io.javalin.websocket.WsHandler import io.javalin.websocket.WsConfig
import suwayomi.tachidesk.manga.impl.download.DownloadManager import suwayomi.tachidesk.manga.impl.download.DownloadManager
object DownloadController { object DownloadController {
/** Download queue stats */ /** Download queue stats */
fun downloadsWS(ws: WsHandler) { fun downloadsWS(ws: WsConfig) {
ws.onConnect { ctx -> ws.onConnect { ctx ->
DownloadManager.addClient(ctx) DownloadManager.addClient(ctx)
DownloadManager.notifyClient(ctx) DownloadManager.notifyClient(ctx)
@@ -18,7 +18,7 @@ object ExtensionController {
/** list all extensions */ /** list all extensions */
fun list(ctx: Context) { fun list(ctx: Context) {
ctx.json( ctx.future(
future { future {
ExtensionsList.getExtensionList() ExtensionsList.getExtensionList()
} }
@@ -29,7 +29,7 @@ object ExtensionController {
fun install(ctx: Context) { fun install(ctx: Context) {
val pkgName = ctx.pathParam("pkgName") val pkgName = ctx.pathParam("pkgName")
ctx.json( ctx.future(
future { future {
Extension.installExtension(pkgName) Extension.installExtension(pkgName)
} }
@@ -42,7 +42,7 @@ object ExtensionController {
val uploadedFile = ctx.uploadedFile("file")!! val uploadedFile = ctx.uploadedFile("file")!!
logger.debug { "Uploaded extension file name: " + uploadedFile.filename } logger.debug { "Uploaded extension file name: " + uploadedFile.filename }
ctx.json( ctx.future(
future { future {
Extension.installExternalExtension(uploadedFile.content, uploadedFile.filename) Extension.installExternalExtension(uploadedFile.content, uploadedFile.filename)
} }
@@ -53,7 +53,7 @@ object ExtensionController {
fun update(ctx: Context) { fun update(ctx: Context) {
val pkgName = ctx.pathParam("pkgName") val pkgName = ctx.pathParam("pkgName")
ctx.json( ctx.future(
future { future {
Extension.updateExtension(pkgName) Extension.updateExtension(pkgName)
} }
@@ -72,7 +72,7 @@ object ExtensionController {
fun icon(ctx: Context) { fun icon(ctx: Context) {
val apkName = ctx.pathParam("apkName") val apkName = ctx.pathParam("apkName")
ctx.result( ctx.future(
future { Extension.getExtensionIcon(apkName) } future { Extension.getExtensionIcon(apkName) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
@@ -19,9 +19,9 @@ object MangaController {
/** get manga info */ /** get manga info */
fun retrieve(ctx: Context) { fun retrieve(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt() 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 { future {
Manga.getManga(mangaId, onlineFetch) Manga.getManga(mangaId, onlineFetch)
} }
@@ -32,7 +32,7 @@ object MangaController {
fun thumbnail(ctx: Context) { fun thumbnail(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt() val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result( ctx.future(
future { Manga.getMangaThumbnail(mangaId) } future { Manga.getMangaThumbnail(mangaId) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
@@ -45,7 +45,7 @@ object MangaController {
fun addToLibrary(ctx: Context) { fun addToLibrary(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt() val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result( ctx.future(
future { Library.addMangaToLibrary(mangaId) } future { Library.addMangaToLibrary(mangaId) }
) )
} }
@@ -54,7 +54,7 @@ object MangaController {
fun removeFromLibrary(ctx: Context) { fun removeFromLibrary(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt() val mangaId = ctx.pathParam("mangaId").toInt()
ctx.result( ctx.future(
future { Library.removeMangaFromLibrary(mangaId) } future { Library.removeMangaFromLibrary(mangaId) }
) )
} }
@@ -97,16 +97,16 @@ object MangaController {
fun chapterList(ctx: Context) { fun chapterList(ctx: Context) {
val mangaId = ctx.pathParam("mangaId").toInt() 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 */ /** used to display a chapter, get a chapter in order to show its pages */
fun chapterRetrieve(ctx: Context) { fun chapterRetrieve(ctx: Context) {
val chapterIndex = ctx.pathParam("chapterIndex").toInt() val chapterIndex = ctx.pathParam("chapterIndex").toInt()
val mangaId = ctx.pathParam("mangaId").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 */ /** used to modify a chapter's parameters */
@@ -143,7 +143,7 @@ object MangaController {
val chapterIndex = ctx.pathParam("chapterIndex").toInt() val chapterIndex = ctx.pathParam("chapterIndex").toInt()
val index = ctx.pathParam("index").toInt() val index = ctx.pathParam("index").toInt()
ctx.result( ctx.future(
future { Page.getPageImage(mangaId, chapterIndex, index) } future { Page.getPageImage(mangaId, chapterIndex, index) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
@@ -30,7 +30,7 @@ object SourceController {
fun popular(ctx: Context) { fun popular(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt() val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json( ctx.future(
future { future {
MangaList.getMangaList(sourceId, pageNum, popular = true) MangaList.getMangaList(sourceId, pageNum, popular = true)
} }
@@ -41,7 +41,7 @@ object SourceController {
fun latest(ctx: Context) { fun latest(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val pageNum = ctx.pathParam("pageNum").toInt() val pageNum = ctx.pathParam("pageNum").toInt()
ctx.json( ctx.future(
future { future {
MangaList.getMangaList(sourceId, pageNum, popular = false) MangaList.getMangaList(sourceId, pageNum, popular = false)
} }
@@ -64,7 +64,7 @@ object SourceController {
/** fetch filters of source with id `sourceId` */ /** fetch filters of source with id `sourceId` */
fun filters(ctx: Context) { fun filters(ctx: Context) {
val sourceId = ctx.pathParam("sourceId").toLong() 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)) ctx.json(Search.getInitialFilterList(sourceId, reset))
} }
@@ -74,7 +74,7 @@ object SourceController {
val sourceId = ctx.pathParam("sourceId").toLong() val sourceId = ctx.pathParam("sourceId").toLong()
val searchTerm = ctx.pathParam("searchTerm") val searchTerm = ctx.pathParam("searchTerm")
val pageNum = ctx.pathParam("pageNum").toInt() 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 */ /** all source search */
@@ -9,6 +9,7 @@ package suwayomi.tachidesk.server
import io.javalin.Javalin import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.path import io.javalin.apibuilder.ApiBuilder.path
import io.javalin.core.security.RouteRole
import io.javalin.http.staticfiles.Location import io.javalin.http.staticfiles.Location
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -86,4 +87,8 @@ object JavalinSetup {
} }
} }
} }
object Auth {
enum class Role : RouteRole { ANYONE, USER_READ, USER_WRITE }
}
} }
@@ -46,7 +46,7 @@ object AppMutex {
} }
return try { return try {
JavalinJackson.fromJson(response, AboutDataClass::class.java) JavalinJackson().fromJsonString(response, AboutDataClass::class.java)
AppMutexState.TachideskInstanceRunning AppMutexState.TachideskInstanceRunning
} catch (e: IOException) { } catch (e: IOException) {
AppMutexState.OtherApplicationRunning AppMutexState.OtherApplicationRunning