correct routes

This commit is contained in:
moehreag 2024-06-17 16:07:56 +02:00
parent e0e35eb97c
commit ddd7bb6ba3
4 changed files with 18 additions and 23 deletions

View file

@ -6,9 +6,10 @@ import dev.frogmc.meta.plugins.configureSerialization
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.engine.* import io.ktor.server.engine.*
import io.ktor.server.netty.* import io.ktor.server.netty.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
val logger = LoggerFactory.getLogger("FrogMC/Meta") val logger: Logger = LoggerFactory.getLogger("FrogMC/Meta")
fun main() { fun main() {

View file

@ -1,7 +1,6 @@
package dev.frogmc.meta.plugins package dev.frogmc.meta.plugins
import dev.frogmc.meta.Config import dev.frogmc.meta.Config
import dev.frogmc.meta.logger
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.response.* import io.ktor.server.response.*
@ -15,11 +14,6 @@ val authPlugin = createRouteScopedPlugin("auth") {
Config.UPLOAD_SECRET.toByteArray() Config.UPLOAD_SECRET.toByteArray()
) )
) { ) {
logger.info(
"Authentication Failed: provided: ${
authorization
}; expected: ${Config.UPLOAD_SECRET}"
)
it.respond(HttpStatusCode.Unauthorized) it.respond(HttpStatusCode.Unauthorized)
} }
} }

View file

@ -29,7 +29,7 @@ fun Application.configureRouting() {
call.respond(transaction(DB.db) { call.respond(transaction(DB.db) {
LoaderVersions LoaderVersions
.select(LoaderVersions.version, LoaderVersions.releaseDate) .select(LoaderVersions.version, LoaderVersions.releaseDate)
.orderBy(LoaderVersions.releaseDate to SortOrder.ASC) .orderBy(LoaderVersions.releaseDate to SortOrder.DESC)
.map { .map {
PartialLoaderVersion( PartialLoaderVersion(
it[LoaderVersions.version], it[LoaderVersions.version],
@ -38,7 +38,7 @@ fun Application.configureRouting() {
} }
}) })
} }
get("/versions/latest") { get("/version/latest") {
val row = transaction(DB.db) { val row = transaction(DB.db) {
LoaderVersions LoaderVersions
.selectAll() .selectAll()
@ -59,7 +59,7 @@ fun Application.configureRouting() {
) )
) )
} }
get("/versions/{version}") { get("/version/{version}") {
val version = call.parameters["version"] ?: return@get call.respond(HttpStatusCode.BadRequest) val version = call.parameters["version"] ?: return@get call.respond(HttpStatusCode.BadRequest)
val row = transaction { val row = transaction {
LoaderVersions LoaderVersions
@ -81,7 +81,7 @@ fun Application.configureRouting() {
) )
) )
} }
route("/versions/upload") { route("/version/upload") {
install(authPlugin) install(authPlugin)
post { post {
val versionObj = call.receive<LoaderVersion>() val versionObj = call.receive<LoaderVersion>()
@ -101,7 +101,7 @@ fun Application.configureRouting() {
call.respond(HttpStatusCode.OK) call.respond(HttpStatusCode.OK)
} }
} }
route("/versions/delete/{version}") { route("/version/delete/{version}") {
install(authPlugin) install(authPlugin)
delete { delete {
val version = val version =
@ -124,11 +124,11 @@ fun Application.configureRouting() {
val versions = DB.getLibraryVersions() val versions = DB.getLibraryVersions()
call.respond(versions) call.respond(versions)
} }
get("/versions/latest") { get("/version/latest") {
val versions = DB.getLibraryVersions() val versions = DB.getLibraryVersions()
call.respond(versions.first()) call.respond(versions.first())
} }
get("/versions/{version}/download") { get("/version/{version}/download") {
val version = call.parameters["version"] ?: return@get call.respond( val version = call.parameters["version"] ?: return@get call.respond(
HttpStatusCode.BadRequest, HttpStatusCode.BadRequest,
"message" to "Invalid version." "message" to "Invalid version."
@ -150,7 +150,7 @@ fun Application.configureRouting() {
val mrVersion = json.decodeFromString<ModrinthVersion>(mrVersionString) val mrVersion = json.decodeFromString<ModrinthVersion>(mrVersionString)
call.respond(mrVersion.files[0]) call.respond(mrVersion.files[0])
} }
get("/versions/{version}") { get("/version/{version}") {
val version = call.parameters["version"] ?: return@get call.respond( val version = call.parameters["version"] ?: return@get call.respond(
HttpStatusCode.BadRequest, HttpStatusCode.BadRequest,
"message" to "Invalid version." "message" to "Invalid version."

View file

@ -18,28 +18,28 @@
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/loader/versions/latest</code> <code>GET /v1/loader/version/latest</code>
<p>Fetches the latest version of FrogMC loader.</p> <p>Fetches the latest version of FrogMC loader.</p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/loader/versions/{version}</code> <code>GET /v1/loader/version/{version}</code>
<p>Fetches a specific version of FrogMC loader.</p> <p>Fetches a specific version of FrogMC loader.</p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/loader/versions/{version}/download</code> <code>GET /v1/loader/version/{version}/download</code>
<p>Fetches the download URL of a specific version of FrogMC loader.</p> <p>Fetches the download URL of a specific version of FrogMC loader.</p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>POST /v1/loader/versions/upload</code> <code>POST /v1/loader/version/upload</code>
<p>Uploads a version of the loader.</p> <p>Uploads a version of the loader.</p>
<p><strong>This endpoint requires authorization.</strong></p> <p><strong>This endpoint requires authorization.</strong></p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>DELETE /v1/loader/versions/delete/{version}</code> <code>DELETE /v1/loader/version/delete/{version}</code>
<p>Deletes a version of the loader.</p> <p>Deletes a version of the loader.</p>
<p><strong>This endpoint requires authorization.</strong></p> <p><strong>This endpoint requires authorization.</strong></p>
</div> </div>
@ -50,17 +50,17 @@
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/library/versions/latest</code> <code>GET /v1/library/version/latest</code>
<p>Fetches the latest version of FrogMC library.</p> <p>Fetches the latest version of FrogMC library.</p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/library/versions/{version}</code> <code>GET /v1/library/version/{version}</code>
<p>Fetches a specific version of FrogMC library.</p> <p>Fetches a specific version of FrogMC library.</p>
</div> </div>
<br> <br>
<div class="route"> <div class="route">
<code>GET /v1/library/versions/{version}/download</code> <code>GET /v1/library/version/{version}/download</code>
<p>Fetches the download URL of a specific version of FrogMC library.</p> <p>Fetches the download URL of a specific version of FrogMC library.</p>
</div> </div>
</div> </div>