forked from SteamWar/SteamWar
Fixes...
This commit is contained in:
@@ -74,27 +74,7 @@ data class UploadSchematic(val name: String, val content: String)
|
||||
fun Route.configureSchematic() {
|
||||
route("/download/{code}") {
|
||||
get {
|
||||
val code = call.parameters["code"] ?: run {
|
||||
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 node = call.receiveSchematic() ?: return@get
|
||||
|
||||
val user = call.principal<SWAuthPrincipal>()?.user
|
||||
if(user != null && !node.accessibleByUser(user)) {
|
||||
@@ -112,36 +92,13 @@ fun Route.configureSchematic() {
|
||||
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 {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
|
||||
val node = SchematicNode.getSchematicNode(dl.nodeId) ?: run {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
val node = call.receiveSchematic() ?: return@get
|
||||
|
||||
call.respond(ResponseSchematic(node))
|
||||
}
|
||||
}
|
||||
route("/schem") {
|
||||
install(SWPermissionCheck)
|
||||
/*get {
|
||||
val user = call.principal<SWAuthPrincipal>()!!.user
|
||||
call.respond(ResponseSchematicList(SchematicNode.list(user, null).filter { it.name != "//copy" }.sortedWith { o1, o2 ->
|
||||
if (o1.isDir || o2.isDir) {
|
||||
o2.isDir.compareTo(o1.isDir)
|
||||
} else {
|
||||
o1.name.compareTo(o2.name)
|
||||
}
|
||||
}.map { ResponseSchematic(it) }, listOf()))
|
||||
}*/
|
||||
|
||||
post {
|
||||
val file = call.receive<UploadSchematic>()
|
||||
@@ -166,64 +123,33 @@ fun Route.configureSchematic() {
|
||||
|
||||
call.respond(ResponseSchematic(node))
|
||||
}
|
||||
/*
|
||||
route("/{id}") {
|
||||
get {
|
||||
val user = call.principal<SWAuthPrincipal>()!!.user
|
||||
val parentId = call.parameters["id"]?.toIntOrNull()
|
||||
if(parentId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
|
||||
val parent = SchematicNode.getSchematicNode(parentId)
|
||||
|
||||
if(parent == null) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
|
||||
if(!parent.accessibleByUser(user)) {
|
||||
call.respond(HttpStatusCode.Forbidden)
|
||||
return@get
|
||||
}
|
||||
|
||||
call.respond(ResponseSchematicLong(parent, parent.generateBreadcrumbs(user)))
|
||||
}
|
||||
|
||||
get("/list") {
|
||||
val user = call.principal<SWAuthPrincipal>()!!.user
|
||||
val parentId = call.parameters["id"]?.toIntOrNull()
|
||||
if(parentId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
|
||||
val parent = SchematicNode.getSchematicNode(parentId)
|
||||
|
||||
if(parent == null) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
|
||||
if(!parent.isDir) {
|
||||
call.respond(HttpStatusCode.BadRequest)
|
||||
return@get
|
||||
}
|
||||
|
||||
if(!parent.accessibleByUser(user)) {
|
||||
call.respond(HttpStatusCode.Forbidden)
|
||||
return@get
|
||||
}
|
||||
|
||||
call.respond(ResponseSchematicList(SchematicNode.list(user, parent.id).filter { it.name != "//copy" }.sortedWith { o1, o2 ->
|
||||
if (o1.isDir || o2.isDir) {
|
||||
o2.isDir.compareTo(o1.isDir)
|
||||
} else {
|
||||
o1.name.compareTo(o2.name)
|
||||
}
|
||||
}.map { ResponseSchematic(it) }, parent.generateBreadcrumbsMap(user).map { ResponseBreadcrumb(it.key, it.value) }))
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ApplicationCall.receiveSchematic(fieldName: String = "code", delete: Boolean = false): SchematicNode? {
|
||||
val code = parameters[fieldName] ?: run {
|
||||
respond(HttpStatusCode.BadRequest)
|
||||
return null
|
||||
}
|
||||
|
||||
val dl = NodeDownload.get(code) ?: run {
|
||||
respond(HttpStatusCode.NotFound)
|
||||
return null
|
||||
}
|
||||
|
||||
if(dl.timestamp.toInstant().plus(Duration.of(5, ChronoUnit.MINUTES)).isBefore(Instant.now())) {
|
||||
respond(HttpStatusCode.Gone)
|
||||
return null
|
||||
}
|
||||
|
||||
if (delete) {
|
||||
dl.delete()
|
||||
}
|
||||
|
||||
val node = SchematicNode.getSchematicNode(dl.nodeId) ?: run {
|
||||
respond(HttpStatusCode.NotFound)
|
||||
return null
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user