From 3d287215e2b397941eb6ad1050bc03fffc982391 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 15 Aug 2024 16:40:25 +0200 Subject: [PATCH] Adapt --- src/main/kotlin/de/steamwar/routes/Data.kt | 8 ++------ src/main/kotlin/de/steamwar/routes/Page.kt | 16 ++++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/de/steamwar/routes/Data.kt b/src/main/kotlin/de/steamwar/routes/Data.kt index 50484bb..040efaa 100644 --- a/src/main/kotlin/de/steamwar/routes/Data.kt +++ b/src/main/kotlin/de/steamwar/routes/Data.kt @@ -56,12 +56,7 @@ data class ResponseUser(val id: Int, val name: String, val uuid: String, val pre fun get(id: Int): ResponseUser { synchronized(cache) { - if(cache.containsKey(id)) { - return cache[id]!! - } - val user = ResponseUser(SteamwarUser.get(id)) - cache[id] = user - return user + return cache[id] ?: ResponseUser(SteamwarUser.get(id)).also { cache[id] = it } } } @@ -109,6 +104,7 @@ fun Route.configureDataRoutes() { call.respond( listOf(UserPerm.PREFIX_ADMIN, UserPerm.PREFIX_DEVELOPER, UserPerm.PREFIX_MODERATOR, UserPerm.PREFIX_SUPPORTER, UserPerm.PREFIX_BUILDER) .associateWith { SteamwarUser.getUsersWithPerm(it) } + .mapKeys { UserPerm.prefixes[it.key]!!.chatPrefix } .mapValues { it.value.map { ResponseUser(it) } } ) } diff --git a/src/main/kotlin/de/steamwar/routes/Page.kt b/src/main/kotlin/de/steamwar/routes/Page.kt index ce99c79..51b766e 100644 --- a/src/main/kotlin/de/steamwar/routes/Page.kt +++ b/src/main/kotlin/de/steamwar/routes/Page.kt @@ -88,7 +88,7 @@ data class PageResponse( } @Serializable -data class CreatePageRequest(val path: String) +data class CreatePageRequest(val path: String, val slug: String?, val title: String?) @Serializable data class CreateBranchRequest(val branch: String) @@ -177,23 +177,23 @@ fun Route.configurePage() { @Serializable data class CreateGiteaPageRequest(val message: String, val content: String, val branch: String, val author: Identity) - val path = call.receive().path - if(path.startsWith("src/content/")) { + val req = call.receive() + if(req.path.startsWith("src/content/")) { call.respond(HttpStatusCode.BadRequest, "Invalid path") return@post } - val res = client.post("repos/SteamWar/Website/contents/src/content/$path") { + val res = client.post("repos/SteamWar/Website/contents/src/content/${req.path}") { contentType(ContentType.Application.Json) setBody(CreateGiteaPageRequest( - "Create page $path", + "Create page ${req.path}", Base64.getEncoder().encodeToString(""" --- - title: [Enter Title] + title: ${req.title ?: "[Enter Title]"} description: [Enter Description] - slug: [Enter Slug] + slug: ${req.slug ?: "[Enter Slug]"} --- - # $path + # ${req.path} """.trimIndent().toByteArray()), call.request.queryParameters["branch"] ?: "master", Identity(call.principal()!!.user.userName, "admin-tool@steamwar.de"