Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation cleanup #417

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object BackupController {
)
},
withResults = {
mime(HttpCode.OK, "application/octet-stream")
stream(HttpCode.OK)
}
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object ExtensionController {
)
},
withResults = {
httpCode(HttpCode.OK)
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
}
)
Expand Down Expand Up @@ -319,7 +320,7 @@ object MangaController {
)
},
withResults = {
mime(HttpCode.OK, "image/*")
image(HttpCode.OK)
httpCode(HttpCode.NOT_FOUND)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down