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)
},
)
}

View File

@@ -7,13 +7,12 @@ package suwayomi.tachidesk.manga.impl
* 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 com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
import eu.kanade.tachiyomi.util.chapter.ChapterSanitizer.sanitize
import io.github.reactivecircus.cache4k.Cache
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.Serializable
@@ -47,8 +46,8 @@ import suwayomi.tachidesk.manga.model.table.toDataClass
import suwayomi.tachidesk.server.serverConfig
import java.time.Instant
import java.util.TreeSet
import java.util.concurrent.TimeUnit
import kotlin.math.max
import kotlin.time.Duration.Companion.minutes
private fun List<ChapterDataClass>.removeDuplicates(currentChapter: ChapterDataClass): List<ChapterDataClass> =
groupBy { it.chapterNumber }
@@ -124,9 +123,9 @@ object Chapter {
}
val map: Cache<Int, Mutex> =
CacheBuilder
.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
Cache
.Builder<Int, Mutex>()
.expireAfterAccess(10.minutes)
.build()
suspend fun fetchChapterList(mangaId: Int): List<SChapter> {

View File

@@ -15,7 +15,7 @@ import eu.kanade.tachiyomi.source.local.LocalSource
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.model.UpdateStrategy
import eu.kanade.tachiyomi.source.online.HttpSource
import io.javalin.http.HttpCode
import io.javalin.http.HttpStatus
import mu.KLogger
import mu.KotlinLogging
import okhttp3.CacheControl
@@ -305,9 +305,9 @@ object Manga {
val tryToRefreshUrl =
!refreshUrl &&
listOf(
HttpCode.GONE.status,
HttpCode.MOVED_PERMANENTLY.status,
HttpCode.NOT_FOUND.status,
HttpStatus.GONE.code,
HttpStatus.MOVED_PERMANENTLY.code,
HttpStatus.NOT_FOUND.code,
523, // (Cloudflare) Origin Is Unreachable
522, // (Cloudflare) Connection timed out
).contains(e.code)

View File

@@ -10,7 +10,8 @@ package suwayomi.tachidesk.manga.impl
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList
import io.javalin.plugin.json.JsonMapper
import io.javalin.json.JsonMapper
import io.javalin.json.fromJsonString
import kotlinx.serialization.Serializable
import suwayomi.tachidesk.manga.impl.MangaList.processEntries
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub
@@ -129,7 +130,7 @@ object Search {
is Filter.CheckBox -> filter.state = change.state.toBooleanStrict()
is Filter.TriState -> filter.state = change.state.toInt()
is Filter.Group<*> -> {
val groupChange = jsonMapper.fromJsonString(change.state, FilterChange::class.java)
val groupChange = jsonMapper.fromJsonString<FilterChange>(change.state)
when (val groupFilter = filter.state[groupChange.position]) {
is Filter.CheckBox -> groupFilter.state = groupChange.state.toBooleanStrict()

View File

@@ -11,7 +11,8 @@ import androidx.preference.Preference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.sourcePreferences
import io.javalin.plugin.json.JsonMapper
import io.javalin.json.JsonMapper
import io.javalin.json.fromJsonString
import mu.KotlinLogging
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert
@@ -131,11 +132,10 @@ object Source {
value: String,
getValue: (Preference) -> Any = { pref ->
println(jsonMapper::class.java.name)
@Suppress("UNCHECKED_CAST")
when (pref.defaultValueType) {
"String" -> value
"Boolean" -> value.toBoolean()
"Set<String>" -> jsonMapper.fromJsonString(value, List::class.java as Class<List<String>>).toSet()
"Set<String>" -> jsonMapper.fromJsonString<List<String>>(value).toSet()
else -> throw RuntimeException("Unsupported type conversion")
}
},

View File

@@ -104,11 +104,11 @@ object DownloadManager {
}
fun addClient(ctx: WsContext) {
clients[ctx.sessionId] = ctx
clients[ctx.sessionId()] = ctx
}
fun removeClient(ctx: WsContext) {
clients.remove(ctx.sessionId)
clients.remove(ctx.sessionId())
}
fun notifyClient(ctx: WsContext) {

View File

@@ -41,7 +41,7 @@ object UpdaterSocket : Websocket<UpdateStatus>() {
}
override fun addClient(ctx: WsContext) {
logger.info { ctx.sessionId }
logger.info { ctx.sessionId() }
super.addClient(ctx)
if (job?.isActive != true) {
job = start()

View File

@@ -8,12 +8,12 @@ abstract class Websocket<T> {
protected val clients = ConcurrentHashMap<String, WsContext>()
open fun addClient(ctx: WsContext) {
clients[ctx.sessionId] = ctx
clients[ctx.sessionId()] = ctx
notifyClient(ctx, null)
}
open fun removeClient(ctx: WsContext) {
clients.remove(ctx.sessionId)
clients.remove(ctx.sessionId())
}
open fun notifyAllClients(value: T) {