Dieser Commit ist enthalten in:
Ursprung
cee09ceebe
Commit
932ad60f0b
@ -1,11 +1,11 @@
|
|||||||
val ktor_version: String by project
|
val ktor_version: String = "2.3.12"
|
||||||
val kotlin_version: String by project
|
val kotlin_version: String = "2.0.10"
|
||||||
val logback_version: String by project
|
val logback_version: String = "1.5.6"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.9.22"
|
kotlin("jvm") version "2.0.10"
|
||||||
id("io.ktor.plugin") version "2.3.7"
|
id("io.ktor.plugin") version "2.3.12"
|
||||||
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.22"
|
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.10"
|
||||||
application
|
application
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -72,43 +72,63 @@ data class SchematicCode(val id: Int, val code: String, val expires: Long)
|
|||||||
data class UploadSchematic(val name: String, val content: String)
|
data class UploadSchematic(val name: String, val content: String)
|
||||||
|
|
||||||
fun Route.configureSchematic() {
|
fun Route.configureSchematic() {
|
||||||
get("/download/{code}") {
|
route("/download/{code}") {
|
||||||
val code = call.parameters["code"] ?: run {
|
get {
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
val code = call.parameters["code"] ?: run {
|
||||||
return@get
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
val dl = NodeDownload.get(code) ?: run {
|
||||||
|
call.respond(HttpStatusCode.NotFound)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
dl.delete()
|
||||||
|
|
||||||
|
if(dl.timestamp.toInstant().plus(Duration.of(5, ChronoUnit.MINUTES)).isBefore(Instant.now())) {
|
||||||
|
call.respond(HttpStatusCode.Gone)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
val node = SchematicNode.getSchematicNode(dl.nodeId) ?: run {
|
||||||
|
call.respond(HttpStatusCode.NotFound)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
val user = call.principal<SWAuthPrincipal>()?.user
|
||||||
|
if(user != null && !node.accessibleByUser(user)) {
|
||||||
|
call.respond(HttpStatusCode.Forbidden)
|
||||||
|
SWException.log("User ${user.userName} tried to download schematic ${node.name} without permission", user.id.toString())
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
val data = NodeData.get(node) ?: run {
|
||||||
|
call.respond(HttpStatusCode.InternalServerError)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
call.response.header("Content-Disposition", "attachment; filename=\"${node.name}.${if (data.nodeFormat) "schem" else "schematic"}\"")
|
||||||
|
call.respondBytes(data.schemData().readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK)
|
||||||
}
|
}
|
||||||
|
get("/info") {
|
||||||
|
val code = call.parameters["code"] ?: run {
|
||||||
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
val dl = NodeDownload.get(code) ?: run {
|
val dl = NodeDownload.get(code) ?: run {
|
||||||
call.respond(HttpStatusCode.NotFound)
|
call.respond(HttpStatusCode.NotFound)
|
||||||
return@get
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
val node = SchematicNode.getSchematicNode(dl.nodeId) ?: run {
|
||||||
|
call.respond(HttpStatusCode.NotFound)
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
call.respond(ResponseSchematic(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
dl.delete()
|
|
||||||
|
|
||||||
if(dl.timestamp.toInstant().plus(Duration.of(5, ChronoUnit.MINUTES)).isBefore(Instant.now())) {
|
|
||||||
call.respond(HttpStatusCode.Gone)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
val node = SchematicNode.getSchematicNode(dl.nodeId) ?: run {
|
|
||||||
call.respond(HttpStatusCode.NotFound)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
val user = call.principal<SWAuthPrincipal>()?.user
|
|
||||||
if(user != null && !node.accessibleByUser(user)) {
|
|
||||||
call.respond(HttpStatusCode.Forbidden)
|
|
||||||
SWException.log("User ${user.userName} tried to download schematic ${node.name} without permission", user.id.toString())
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
val data = NodeData.get(node) ?: run {
|
|
||||||
call.respond(HttpStatusCode.InternalServerError)
|
|
||||||
return@get
|
|
||||||
}
|
|
||||||
|
|
||||||
call.response.header("Content-Disposition", "attachment; filename=\"${node.name}.${if (data.nodeFormat) "schem" else "schematic"}\"")
|
|
||||||
call.respondBytes(data.schemData().readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK)
|
|
||||||
}
|
}
|
||||||
route("/schem") {
|
route("/schem") {
|
||||||
install(SWPermissionCheck)
|
install(SWPermissionCheck)
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren