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

View File

@@ -92,7 +92,7 @@ object BackupController {
) )
}, },
withResults = { withResults = {
mime(HttpCode.OK, "application/octet-stream") stream(HttpCode.OK)
} }
) )
@@ -124,7 +124,7 @@ object BackupController {
) )
}, },
withResults = { withResults = {
mime(HttpCode.OK, "application/octet-stream") stream(HttpCode.OK)
} }
) )

View File

@@ -158,7 +158,7 @@ object ExtensionController {
) )
}, },
withResults = { withResults = {
httpCode(HttpCode.OK) image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND) httpCode(HttpCode.NOT_FOUND)
} }
) )

View File

@@ -23,6 +23,7 @@ import suwayomi.tachidesk.server.util.handler
import suwayomi.tachidesk.server.util.pathParam import suwayomi.tachidesk.server.util.pathParam
import suwayomi.tachidesk.server.util.queryParam import suwayomi.tachidesk.server.util.queryParam
import suwayomi.tachidesk.server.util.withOperation import suwayomi.tachidesk.server.util.withOperation
import kotlin.time.Duration.Companion.days
object MangaController { object MangaController {
/** get manga info */ /** get manga info */
@@ -63,14 +64,14 @@ object MangaController {
future { Manga.getMangaThumbnail(mangaId, useCache) } future { Manga.getMangaThumbnail(mangaId, useCache) }
.thenApply { .thenApply {
ctx.header("content-type", it.second) ctx.header("content-type", it.second)
val httpCacheSeconds = 60 * 60 * 24 val httpCacheSeconds = 1.days.inWholeSeconds
ctx.header("cache-control", "max-age=$httpCacheSeconds") ctx.header("cache-control", "max-age=$httpCacheSeconds")
it.first it.first
} }
) )
}, },
withResults = { withResults = {
mime(HttpCode.OK, "image/*") image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND) httpCode(HttpCode.NOT_FOUND)
} }
) )
@@ -319,7 +320,7 @@ object MangaController {
) )
}, },
withResults = { withResults = {
mime(HttpCode.OK, "image/*") image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND) httpCode(HttpCode.NOT_FOUND)
} }
) )

View File

@@ -152,8 +152,14 @@ class ResultsBuilder {
fun plainText(code: HttpCode) { fun plainText(code: HttpCode) {
results += ResultType.MimeType(code, "text/plain", String::class.java) results += ResultType.MimeType(code, "text/plain", String::class.java)
} }
fun mime(code: HttpCode, mime: String) { fun image(code: HttpCode) {
results += ResultType.MimeType(code, mime, null) 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) { fun httpCode(code: HttpCode) {
results += ResultType.StatusCode(code) results += ResultType.StatusCode(code)
@@ -162,9 +168,9 @@ class ResultsBuilder {
sealed class ResultType { sealed class ResultType {
abstract fun applyTo(documentation: OpenApiDocumentation) 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) { 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() { data class StatusCode(val code: HttpCode) : ResultType() {