mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-26 04:31:04 +00:00
feat: Add static file paths to remove env specific files in resources
This commit is contained in:
@@ -4,8 +4,12 @@ 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.http.content.*
|
||||
import io.ktor.server.plugins.cachingheaders.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.time.Duration
|
||||
|
||||
internal suspend fun ApplicationCall.respondOrNotFound(value: Any?) = respond(value ?: HttpStatusCode.NotFound)
|
||||
@@ -25,3 +29,14 @@ internal fun ApplicationCallPipeline.installCache(cacheControl: CacheControl) =
|
||||
|
||||
internal fun ApplicationCallPipeline.installNotarizedRoute(configure: NotarizedRoute.Config.() -> Unit = {}) =
|
||||
install(NotarizedRoute(), configure)
|
||||
|
||||
internal fun Route.staticFiles(
|
||||
remotePath: String,
|
||||
dir: Path,
|
||||
block: StaticContentConfig<File>.() -> Unit = {
|
||||
contentType {
|
||||
ContentType.Application.Json
|
||||
}
|
||||
extensions("json")
|
||||
},
|
||||
) = staticFiles(remotePath, dir.toFile(), null, block)
|
||||
|
||||
@@ -8,9 +8,7 @@ import app.revanced.api.configuration.routes.oldApiRoute
|
||||
import app.revanced.api.configuration.routes.patchesRoute
|
||||
import io.bkbn.kompendium.core.routes.redoc
|
||||
import io.bkbn.kompendium.core.routes.swagger
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.http.content.*
|
||||
import io.ktor.server.routing.*
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
import org.koin.ktor.ext.get as koinGet
|
||||
@@ -27,10 +25,7 @@ internal fun Application.configureRouting() = routing {
|
||||
apiRoute()
|
||||
}
|
||||
|
||||
staticResources("/", "/app/revanced/api/static/root") {
|
||||
contentType { ContentType.Application.Json }
|
||||
extensions("json")
|
||||
}
|
||||
staticFiles("/", configuration.staticFilesPath)
|
||||
|
||||
swagger(pageTitle = "ReVanced API", path = "/")
|
||||
redoc(pageTitle = "ReVanced API", path = "/redoc")
|
||||
|
||||
@@ -11,6 +11,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* The repository storing the configuration for the API.
|
||||
@@ -24,6 +25,8 @@ import java.io.File
|
||||
* @property corsAllowedHosts The hosts allowed to make requests to the API.
|
||||
* @property endpoint The endpoint of the API.
|
||||
* @property oldApiEndpoint The endpoint of the old API to proxy requests to.
|
||||
* @property staticFilesPath The path to the static files to be served under the root path.
|
||||
* @property versionedStaticFilesPath The path to the static files to be served under a versioned path.
|
||||
*/
|
||||
@Serializable
|
||||
internal class ConfigurationRepository(
|
||||
@@ -40,6 +43,12 @@ internal class ConfigurationRepository(
|
||||
val endpoint: String,
|
||||
@SerialName("old-api-endpoint")
|
||||
val oldApiEndpoint: String,
|
||||
@Serializable(with = PathSerializer::class)
|
||||
@SerialName("static-files-path")
|
||||
val staticFilesPath: Path,
|
||||
@Serializable(with = PathSerializer::class)
|
||||
@SerialName("versioned-static-files-path")
|
||||
val versionedStaticFilesPath: Path,
|
||||
) {
|
||||
/**
|
||||
* Am asset configuration whose asset is signed.
|
||||
@@ -108,3 +117,11 @@ private object FileSerializer : KSerializer<File> {
|
||||
|
||||
override fun deserialize(decoder: Decoder) = File(decoder.decodeString())
|
||||
}
|
||||
|
||||
private object PathSerializer : KSerializer<Path> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Path", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Path) = encoder.encodeString(value.toString())
|
||||
|
||||
override fun deserialize(decoder: Decoder) = Path.of(decoder.decodeString())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package app.revanced.api.configuration.routes
|
||||
|
||||
import app.revanced.api.configuration.*
|
||||
import app.revanced.api.configuration.installCache
|
||||
import app.revanced.api.configuration.installNoCache
|
||||
import app.revanced.api.configuration.installNotarizedRoute
|
||||
@@ -13,7 +14,6 @@ import io.bkbn.kompendium.core.metadata.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.auth.*
|
||||
import io.ktor.server.http.content.*
|
||||
import io.ktor.server.plugins.ratelimit.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
@@ -75,10 +75,7 @@ internal fun Route.apiRoute() {
|
||||
}
|
||||
}
|
||||
|
||||
staticResources("/", "/app/revanced/api/static/versioned") {
|
||||
contentType { ContentType.Application.Json }
|
||||
extensions("json")
|
||||
}
|
||||
staticFiles("/", apiService.versionedStaticFilesPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ internal class ApiService(
|
||||
private val backendRepository: BackendRepository,
|
||||
private val configurationRepository: ConfigurationRepository,
|
||||
) {
|
||||
val versionedStaticFilesPath = configurationRepository.versionedStaticFilesPath
|
||||
|
||||
suspend fun contributors() = withContext(Dispatchers.IO) {
|
||||
configurationRepository.contributorsRepositoryNames.map {
|
||||
async {
|
||||
|
||||
Reference in New Issue
Block a user