Update dependency io.javalin:javalin to v6 (#1152)

* Update dependency io.javalin:javalin to v6

* Simple compile fixes

* Simple compile fixes pass 2

* Add results to futures

* Setup jetty server and api routes

* Setup Cors

* Setup basic auth

* Documentation stubs

* Replace chapter mutex cache

* Fix compile

* Disable Jetty Logging

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Syer10 <syer10@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2024-11-17 15:00:53 -05:00
committed by GitHub
parent ba1c2845b6
commit 9cd8cb3d54
31 changed files with 478 additions and 363 deletions

View File

@@ -1,6 +1,6 @@
package suwayomi.tachidesk.manga.controller
import io.javalin.http.HttpCode
import io.javalin.http.HttpStatus
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupExport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
@@ -28,14 +28,16 @@ object BackupController {
}
},
behaviorOf = { ctx ->
ctx.future(
ctx.future {
future {
ProtoBackupImport.restoreLegacy(ctx.bodyAsInputStream())
},
)
ProtoBackupImport.restoreLegacy(ctx.bodyInputStream())
}.thenApply {
ctx.json(it)
}
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -54,15 +56,17 @@ object BackupController {
},
behaviorOf = { ctx ->
// TODO: rewrite this with ctx.uploadedFiles(), don't call the multipart field "backup.proto.gz"
ctx.future(
ctx.future {
future {
ProtoBackupImport.restoreLegacy(ctx.uploadedFile("backup.proto.gz")!!.content)
},
)
ProtoBackupImport.restoreLegacy(ctx.uploadedFile("backup.proto.gz")!!.content())
}.thenApply {
ctx.json(it)
}
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -77,7 +81,7 @@ object BackupController {
},
behaviorOf = { ctx ->
ctx.contentType("application/octet-stream")
ctx.future(
ctx.future {
future {
ProtoBackupExport.createBackup(
BackupFlags(
@@ -88,11 +92,11 @@ object BackupController {
includeHistory = true,
),
)
},
)
}.thenApply { ctx.result(it) }
}
},
withResults = {
stream(HttpCode.OK)
stream(HttpStatus.OK)
},
)
@@ -109,7 +113,7 @@ object BackupController {
ctx.contentType("application/octet-stream")
ctx.header("Content-Disposition", """attachment; filename="${Backup.getFilename()}"""")
ctx.future(
ctx.future {
future {
ProtoBackupExport.createBackup(
BackupFlags(
@@ -120,11 +124,11 @@ object BackupController {
includeHistory = true,
),
)
},
)
}.thenApply { ctx.result(it) }
}
},
withResults = {
stream(HttpCode.OK)
stream(HttpStatus.OK)
},
)
@@ -138,14 +142,16 @@ object BackupController {
}
},
behaviorOf = { ctx ->
ctx.future(
ctx.future {
future {
ProtoBackupValidator.validate(ctx.bodyAsInputStream())
},
)
ProtoBackupValidator.validate(ctx.bodyInputStream())
}.thenApply {
ctx.json(it)
}
}
},
withResults = {
json<ProtoBackupValidator.ValidationResult>(HttpCode.OK)
json<ProtoBackupValidator.ValidationResult>(HttpStatus.OK)
},
)
@@ -167,14 +173,16 @@ object BackupController {
}
},
behaviorOf = { ctx ->
ctx.future(
ctx.future {
future {
ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content)
},
)
ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content())
}.thenApply {
ctx.json(it)
}
}
},
withResults = {
json<ProtoBackupValidator.ValidationResult>(HttpCode.OK)
json<ProtoBackupValidator.ValidationResult>(HttpStatus.OK)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import suwayomi.tachidesk.manga.impl.Category
import suwayomi.tachidesk.manga.impl.CategoryManga
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
@@ -31,7 +31,7 @@ object CategoryController {
ctx.json(Category.getCategoryList())
},
withResults = {
json<Array<CategoryDataClass>>(HttpCode.OK)
json<Array<CategoryDataClass>>(HttpStatus.OK)
},
)
@@ -49,12 +49,12 @@ object CategoryController {
if (Category.createCategory(name) != -1) {
ctx.status(200)
} else {
ctx.status(HttpCode.BAD_REQUEST)
ctx.status(HttpStatus.BAD_REQUEST)
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.BAD_REQUEST)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.BAD_REQUEST)
},
)
@@ -77,7 +77,7 @@ object CategoryController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -96,7 +96,7 @@ object CategoryController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -114,7 +114,7 @@ object CategoryController {
ctx.json(CategoryManga.getCategoryMangaList(categoryId))
},
withResults = {
json<Array<MangaDataClass>>(HttpCode.OK)
json<Array<MangaDataClass>>(HttpStatus.OK)
},
)
@@ -134,7 +134,7 @@ object CategoryController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -155,8 +155,8 @@ object CategoryController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import io.javalin.websocket.WsConfig
import kotlinx.serialization.json.Json
import suwayomi.tachidesk.manga.impl.download.DownloadManager
@@ -48,7 +48,7 @@ object DownloadController {
DownloadManager.start()
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -62,12 +62,13 @@ object DownloadController {
}
},
behaviorOf = { ctx ->
ctx.future(
future { DownloadManager.stop() },
)
ctx.future {
future { DownloadManager.stop() }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -81,12 +82,13 @@ object DownloadController {
}
},
behaviorOf = { ctx ->
ctx.future(
future { DownloadManager.clear() },
)
ctx.future {
future { DownloadManager.clear() }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -102,15 +104,15 @@ object DownloadController {
}
},
behaviorOf = { ctx, chapterIndex, mangaId ->
ctx.future(
ctx.future {
future {
DownloadManager.enqueueWithChapterIndex(mangaId, chapterIndex)
},
)
}.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -125,14 +127,14 @@ object DownloadController {
},
behaviorOf = { ctx ->
val inputs = json.decodeFromString<EnqueueInput>(ctx.body())
ctx.future(
ctx.future {
future {
DownloadManager.enqueue(inputs)
},
)
}.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -148,14 +150,14 @@ object DownloadController {
},
behaviorOf = { ctx ->
val input = json.decodeFromString<EnqueueInput>(ctx.body())
ctx.future(
ctx.future {
future {
DownloadManager.dequeue(input)
},
)
}.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -176,7 +178,7 @@ object DownloadController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -196,7 +198,7 @@ object DownloadController {
DownloadManager.reorder(chapterIndex, mangaId, to)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import mu.KotlinLogging
import suwayomi.tachidesk.manga.impl.extension.Extension
import suwayomi.tachidesk.manga.impl.extension.ExtensionsList
@@ -31,14 +31,16 @@ object ExtensionController {
}
},
behaviorOf = { ctx ->
ctx.future(
ctx.future {
future {
ExtensionsList.getExtensionList()
},
)
}.thenApply {
ctx.json(it)
}
}
},
withResults = {
json<Array<ExtensionDataClass>>(HttpCode.OK)
json<Array<ExtensionDataClass>>(HttpStatus.OK)
},
)
@@ -53,16 +55,18 @@ object ExtensionController {
}
},
behaviorOf = { ctx, pkgName ->
ctx.future(
ctx.future {
future {
Extension.installExtension(pkgName)
},
)
}.thenApply {
ctx.status(it)
}
}
},
withResults = {
httpCode(HttpCode.CREATED)
httpCode(HttpCode.FOUND)
httpCode(HttpCode.INTERNAL_SERVER_ERROR)
httpCode(HttpStatus.CREATED)
httpCode(HttpStatus.FOUND)
httpCode(HttpStatus.INTERNAL_SERVER_ERROR)
},
)
@@ -81,18 +85,23 @@ object ExtensionController {
},
behaviorOf = { ctx ->
val uploadedFile = ctx.uploadedFile("file")!!
logger.debug { "Uploaded extension file name: " + uploadedFile.filename }
logger.debug { "Uploaded extension file name: " + uploadedFile.filename() }
ctx.future(
ctx.future {
future {
Extension.installExternalExtension(uploadedFile.content, uploadedFile.filename)
},
)
Extension.installExternalExtension(
uploadedFile.content(),
uploadedFile.filename(),
)
}.thenApply {
ctx.status(it)
}
}
},
withResults = {
httpCode(HttpCode.CREATED)
httpCode(HttpCode.FOUND)
httpCode(HttpCode.INTERNAL_SERVER_ERROR)
httpCode(HttpStatus.CREATED)
httpCode(HttpStatus.FOUND)
httpCode(HttpStatus.INTERNAL_SERVER_ERROR)
},
)
@@ -107,17 +116,19 @@ object ExtensionController {
}
},
behaviorOf = { ctx, pkgName ->
ctx.future(
ctx.future {
future {
Extension.updateExtension(pkgName)
},
)
}.thenApply {
ctx.status(it)
}
}
},
withResults = {
httpCode(HttpCode.CREATED)
httpCode(HttpCode.FOUND)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpCode.INTERNAL_SERVER_ERROR)
httpCode(HttpStatus.CREATED)
httpCode(HttpStatus.FOUND)
httpCode(HttpStatus.NOT_FOUND)
httpCode(HttpStatus.INTERNAL_SERVER_ERROR)
},
)
@@ -136,10 +147,10 @@ object ExtensionController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.CREATED)
httpCode(HttpCode.FOUND)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpCode.INTERNAL_SERVER_ERROR)
httpCode(HttpStatus.CREATED)
httpCode(HttpStatus.FOUND)
httpCode(HttpStatus.NOT_FOUND)
httpCode(HttpStatus.INTERNAL_SERVER_ERROR)
},
)
@@ -154,19 +165,19 @@ object ExtensionController {
}
},
behaviorOf = { ctx, apkName ->
ctx.future(
ctx.future {
future { Extension.getExtensionIcon(apkName) }
.thenApply {
ctx.header("content-type", it.second)
val httpCacheSeconds = 365.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds, immutable")
it.first
},
)
ctx.result(it.first)
}
}
},
withResults = {
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
image(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import kotlinx.serialization.json.Json
import suwayomi.tachidesk.manga.impl.CategoryManga
import suwayomi.tachidesk.manga.impl.Chapter
@@ -41,15 +41,15 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId, onlineFetch ->
ctx.future(
ctx.future {
future {
Manga.getManga(mangaId, onlineFetch)
},
)
}.thenApply { ctx.json(it) }
}
},
withResults = {
json<MangaDataClass>(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
json<MangaDataClass>(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -65,15 +65,15 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId, onlineFetch ->
ctx.future(
ctx.future {
future {
Manga.getMangaFull(mangaId, onlineFetch)
},
)
}.thenApply { ctx.json(it) }
}
},
withResults = {
json<MangaDataClass>(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
json<MangaDataClass>(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -88,19 +88,19 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId ->
ctx.future(
ctx.future {
future { Manga.getMangaThumbnail(mangaId) }
.thenApply {
ctx.header("content-type", it.second)
val httpCacheSeconds = 1.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds")
it.first
},
)
ctx.result(it.first)
}
}
},
withResults = {
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
image(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -115,13 +115,14 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId ->
ctx.future(
future { Library.addMangaToLibrary(mangaId) },
)
ctx.future {
future { Library.addMangaToLibrary(mangaId) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -136,13 +137,14 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId ->
ctx.future(
future { Library.removeMangaFromLibrary(mangaId) },
)
ctx.future {
future { Library.removeMangaFromLibrary(mangaId) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -160,7 +162,7 @@ object MangaController {
ctx.json(CategoryManga.getMangaCategories(mangaId))
},
withResults = {
json<Array<CategoryDataClass>>(HttpCode.OK)
json<Array<CategoryDataClass>>(HttpStatus.OK)
},
)
@@ -180,7 +182,7 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -200,7 +202,7 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -221,8 +223,8 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -242,11 +244,14 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId, onlineFetch ->
ctx.future(future { Chapter.getChapterList(mangaId, onlineFetch) })
ctx.future {
future { Chapter.getChapterList(mangaId, onlineFetch) }
.thenApply { ctx.json(it) }
}
},
withResults = {
json<Array<ChapterDataClass>>(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
json<Array<ChapterDataClass>>(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -266,7 +271,7 @@ object MangaController {
Chapter.modifyChapters(input, mangaId)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -291,7 +296,7 @@ object MangaController {
)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -307,11 +312,14 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId, chapterIndex ->
ctx.future(future { getChapterDownloadReadyByIndex(chapterIndex, mangaId) })
ctx.future {
future { getChapterDownloadReadyByIndex(chapterIndex, mangaId) }
.thenApply { ctx.json(it) }
}
},
withResults = {
json<ChapterDataClass>(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
json<ChapterDataClass>(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -336,7 +344,7 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -357,8 +365,8 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -381,8 +389,8 @@ object MangaController {
ctx.status(200)
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -401,19 +409,19 @@ object MangaController {
}
},
behaviorOf = { ctx, mangaId, chapterIndex, index ->
ctx.future(
ctx.future {
future { Page.getPageImage(mangaId, chapterIndex, index) }
.thenApply {
ctx.header("content-type", it.second)
val httpCacheSeconds = 1.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds")
it.first
},
)
ctx.result(it.first)
}
}
},
withResults = {
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
image(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import kotlinx.serialization.json.Json
import suwayomi.tachidesk.manga.impl.MangaList
import suwayomi.tachidesk.manga.impl.Search
@@ -38,7 +38,7 @@ object SourceController {
ctx.json(Source.getSourceList())
},
withResults = {
json<Array<SourceDataClass>>(HttpCode.OK)
json<Array<SourceDataClass>>(HttpStatus.OK)
},
)
@@ -56,8 +56,8 @@ object SourceController {
ctx.json(Source.getSource(sourceId)!!)
},
withResults = {
json<SourceDataClass>(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
json<SourceDataClass>(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -73,14 +73,14 @@ object SourceController {
}
},
behaviorOf = { ctx, sourceId, pageNum ->
ctx.future(
ctx.future {
future {
MangaList.getMangaList(sourceId, pageNum, popular = true)
},
)
}.thenApply { ctx.json(it) }
}
},
withResults = {
json<PagedMangaListDataClass>(HttpCode.OK)
json<PagedMangaListDataClass>(HttpStatus.OK)
},
)
@@ -96,14 +96,14 @@ object SourceController {
}
},
behaviorOf = { ctx, sourceId, pageNum ->
ctx.future(
ctx.future {
future {
MangaList.getMangaList(sourceId, pageNum, popular = false)
},
)
}.thenApply { ctx.json(it) }
}
},
withResults = {
json<PagedMangaListDataClass>(HttpCode.OK)
json<PagedMangaListDataClass>(HttpStatus.OK)
},
)
@@ -121,7 +121,7 @@ object SourceController {
ctx.json(Source.getSourcePreferences(sourceId))
},
withResults = {
json<Array<Source.PreferenceObject>>(HttpCode.OK)
json<Array<Source.PreferenceObject>>(HttpStatus.OK)
},
)
@@ -141,7 +141,7 @@ object SourceController {
ctx.json(Source.setSourcePreference(sourceId, preferenceChange.position, preferenceChange.value))
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -160,7 +160,7 @@ object SourceController {
ctx.json(Search.getFilterList(sourceId, reset))
},
withResults = {
json<Array<Search.FilterObject>>(HttpCode.OK)
json<Array<Search.FilterObject>>(HttpStatus.OK)
},
)
@@ -189,7 +189,7 @@ object SourceController {
ctx.json(Search.setFilter(sourceId, filterChange))
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -206,10 +206,13 @@ object SourceController {
}
},
behaviorOf = { ctx, sourceId, searchTerm, pageNum ->
ctx.future(future { Search.sourceSearch(sourceId, searchTerm, pageNum) })
ctx.future {
future { Search.sourceSearch(sourceId, searchTerm, pageNum) }
.thenApply { ctx.json(it) }
}
},
withResults = {
json<PagedMangaListDataClass>(HttpCode.OK)
json<PagedMangaListDataClass>(HttpStatus.OK)
},
)
@@ -227,10 +230,13 @@ object SourceController {
},
behaviorOf = { ctx, sourceId, pageNum ->
val filter = json.decodeFromString<FilterData>(ctx.body())
ctx.future(future { Search.sourceFilter(sourceId, pageNum, filter) })
ctx.future {
future { Search.sourceFilter(sourceId, pageNum, filter) }
.thenApply { ctx.json(it) }
}
},
withResults = {
json<PagedMangaListDataClass>(HttpCode.OK)
json<PagedMangaListDataClass>(HttpStatus.OK)
},
)
@@ -249,7 +255,7 @@ object SourceController {
ctx.json(Search.sourceGlobalSearch(searchTerm))
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
}

View File

@@ -7,7 +7,7 @@ package suwayomi.tachidesk.manga.controller
* 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.HttpCode
import io.javalin.http.HttpStatus
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import suwayomi.tachidesk.manga.impl.track.Track
@@ -36,7 +36,7 @@ object TrackController {
ctx.json(Track.getTrackerList())
},
withResults = {
json<Array<TrackerDataClass>>(HttpCode.OK)
json<Array<TrackerDataClass>>(HttpStatus.OK)
},
)
@@ -52,11 +52,14 @@ object TrackController {
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.LoginInput>(ctx.body())
logger.debug { "tracker login $input" }
ctx.future(future { Track.login(input) })
ctx.future {
future { Track.login(input) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -72,11 +75,14 @@ object TrackController {
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.LogoutInput>(ctx.body())
logger.debug { "tracker logout $input" }
ctx.future(future { Track.logout(input) })
ctx.future {
future { Track.logout(input) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -92,11 +98,14 @@ object TrackController {
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.SearchInput>(ctx.body())
logger.debug { "tracker search $input" }
ctx.future(future { Track.search(input) })
ctx.future {
future { Track.search(input) }
.thenApply { ctx.json(it) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
@@ -112,10 +121,13 @@ object TrackController {
}
},
behaviorOf = { ctx, mangaId, trackerId, remoteId ->
ctx.future(future { Track.bind(mangaId, trackerId, remoteId.toLong()) })
ctx.future {
future { Track.bind(mangaId, trackerId, remoteId.toLong()) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -131,10 +143,13 @@ object TrackController {
behaviorOf = { ctx ->
val input = json.decodeFromString<Track.UpdateInput>(ctx.body())
logger.debug { "tracker update $input" }
ctx.future(future { Track.update(input) })
ctx.future {
future { Track.update(input) }
.thenApply { ctx.status(HttpStatus.OK) }
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
@@ -148,19 +163,19 @@ object TrackController {
}
},
behaviorOf = { ctx, trackerId ->
ctx.future(
ctx.future {
future { Track.getTrackerThumbnail(trackerId) }
.thenApply {
ctx.header("content-type", it.second)
val httpCacheSeconds = 1.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds")
it.first
},
)
ctx.result(it.first)
}
}
},
withResults = {
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
image(HttpStatus.OK)
httpCode(HttpStatus.NOT_FOUND)
},
)
}

View File

@@ -1,6 +1,6 @@
package suwayomi.tachidesk.manga.controller
import io.javalin.http.HttpCode
import io.javalin.http.HttpStatus
import io.javalin.websocket.WsConfig
import mu.KotlinLogging
import suwayomi.tachidesk.manga.impl.Category
@@ -39,14 +39,14 @@ object UpdateController {
}
},
behaviorOf = { ctx, pageNum ->
ctx.future(
ctx.future {
future {
Chapter.getRecentChapters(pageNum)
},
)
}.thenApply { ctx.json(it) }
}
},
withResults = {
json<PagedMangaChapterListDataClass>(HttpCode.OK)
json<PagedMangaChapterListDataClass>(HttpStatus.OK)
},
)
@@ -84,13 +84,13 @@ object UpdateController {
)
} else {
logger.info { "No Category found" }
ctx.status(HttpCode.BAD_REQUEST)
ctx.status(HttpStatus.BAD_REQUEST)
}
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpCode.BAD_REQUEST)
httpCode(HttpStatus.OK)
httpCode(HttpStatus.BAD_REQUEST)
},
)
@@ -119,7 +119,7 @@ object UpdateController {
ctx.json(updater.statusDeprecated.value)
},
withResults = {
json<UpdateStatus>(HttpCode.OK)
json<UpdateStatus>(HttpStatus.OK)
},
)
@@ -134,16 +134,16 @@ object UpdateController {
behaviorOf = { ctx ->
val updater = Injekt.get<IUpdater>()
logger.info { "Resetting Updater" }
ctx.future(
ctx.future {
future {
updater.reset()
}.thenApply {
ctx.status(HttpCode.OK)
},
)
ctx.status(HttpStatus.OK)
}
}
},
withResults = {
httpCode(HttpCode.OK)
httpCode(HttpStatus.OK)
},
)
}