feat: Add OpenAPI docs and cache to routes

This commit is contained in:
oSumAtrIX
2024-06-09 01:28:33 +02:00
parent 205bcde77a
commit 6ea63be490
14 changed files with 592 additions and 124 deletions

View File

@@ -1,7 +1,27 @@
package app.revanced.api.configuration
import io.bkbn.kompendium.core.plugin.NotarizedRoute
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.plugins.cachingheaders.*
import io.ktor.server.response.*
import kotlin.time.Duration
suspend fun ApplicationCall.respondOrNotFound(value: Any?) = respond(value ?: HttpStatusCode.NotFound)
internal suspend fun ApplicationCall.respondOrNotFound(value: Any?) = respond(value ?: HttpStatusCode.NotFound)
internal fun ApplicationCallPipeline.installCache(maxAge: Duration) =
installCache(CacheControl.MaxAge(maxAgeSeconds = maxAge.inWholeSeconds.toInt()))
internal fun ApplicationCallPipeline.installNoCache() =
installCache(CacheControl.NoCache(null))
internal fun ApplicationCallPipeline.installCache(cacheControl: CacheControl) =
install(CachingHeaders) {
options { _, _ ->
CachingOptions(cacheControl)
}
}
internal fun ApplicationCallPipeline.installNotarizedRoute(configure: NotarizedRoute.Config.() -> Unit = {}) =
install(NotarizedRoute(), configure)