Documentation cleanup (#417)

This commit is contained in:
Mitchell Syer
2022-10-11 05:24:45 -04:00
committed by GitHub
parent f2d1c6e3cb
commit 71730fddad
4 changed files with 17 additions and 10 deletions
@@ -92,7 +92,7 @@ object BackupController {
)
},
withResults = {
mime(HttpCode.OK, "application/octet-stream")
stream(HttpCode.OK)
}
)
@@ -124,7 +124,7 @@ object BackupController {
)
},
withResults = {
mime(HttpCode.OK, "application/octet-stream")
stream(HttpCode.OK)
}
)
@@ -158,7 +158,7 @@ object ExtensionController {
)
},
withResults = {
httpCode(HttpCode.OK)
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
}
)
@@ -23,6 +23,7 @@ import suwayomi.tachidesk.server.util.handler
import suwayomi.tachidesk.server.util.pathParam
import suwayomi.tachidesk.server.util.queryParam
import suwayomi.tachidesk.server.util.withOperation
import kotlin.time.Duration.Companion.days
object MangaController {
/** get manga info */
@@ -63,14 +64,14 @@ object MangaController {
future { Manga.getMangaThumbnail(mangaId, useCache) }
.thenApply {
ctx.header("content-type", it.second)
val httpCacheSeconds = 60 * 60 * 24
val httpCacheSeconds = 1.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds")
it.first
}
)
},
withResults = {
mime(HttpCode.OK, "image/*")
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
}
)
@@ -319,7 +320,7 @@ object MangaController {
)
},
withResults = {
mime(HttpCode.OK, "image/*")
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
}
)
@@ -152,8 +152,14 @@ class ResultsBuilder {
fun plainText(code: HttpCode) {
results += ResultType.MimeType(code, "text/plain", String::class.java)
}
fun mime(code: HttpCode, mime: String) {
results += ResultType.MimeType(code, mime, null)
fun image(code: HttpCode) {
results += ResultType.MimeType(code, "image/*", ByteArray::class.java)
}
fun stream(code: HttpCode) {
results += ResultType.MimeType(code, "application/octet-stream", ByteArray::class.java)
}
inline fun <reified T> mime(code: HttpCode, mime: String) {
results += ResultType.MimeType(code, mime, T::class.java)
}
fun httpCode(code: HttpCode) {
results += ResultType.StatusCode(code)
@@ -162,9 +168,9 @@ class ResultsBuilder {
sealed class ResultType {
abstract fun applyTo(documentation: OpenApiDocumentation)
data class MimeType(val code: HttpCode, val mime: String, private val clazz: Class<*>?) : ResultType() {
data class MimeType(val code: HttpCode, val mime: String, private val clazz: Class<*>) : ResultType() {
override fun applyTo(documentation: OpenApiDocumentation) {
documentation.result(code.status.toString(), clazz)
documentation.result(code.status.toString(), clazz, mime)
}
}
data class StatusCode(val code: HttpCode) : ResultType() {