From cb003d235fadba47391be733cc49cb1b2e5f7cfc Mon Sep 17 00:00:00 2001 From: Sisi Date: Sat, 2 May 2026 13:01:14 +0200 Subject: [PATCH] add channel set desc --- main.go | 1 + packages/httpRequest/hubs.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/main.go b/main.go index b21698d..2fa8da5 100644 --- a/main.go +++ b/main.go @@ -83,6 +83,7 @@ func main() { http.HandleFunc("PUT /hub/channel", withCORS(httpRequest.HandleChannelCreate)) http.HandleFunc("DELETE /hub/channel", withCORS(httpRequest.HandleChannelRemove)) http.HandleFunc("PATCH /hub/name", withCORS(httpRequest.HandleChannelSetName)) + http.HandleFunc("PATCH /hub/description", withCORS(httpRequest.HandleChannelSetDescription)) http.HandleFunc("POST /connection/message", withCORS(httpRequest.HandleDm)) http.HandleFunc("GET /ws", wsServer.ServeWsConnection) diff --git a/packages/httpRequest/hubs.go b/packages/httpRequest/hubs.go index 3582e1b..a44eafa 100644 --- a/packages/httpRequest/hubs.go +++ b/packages/httpRequest/hubs.go @@ -870,3 +870,27 @@ func HandleChannelSetName(response http.ResponseWriter, request *http.Request) { response.WriteHeader(http.StatusAccepted) } + +func HandleChannelSetDescription(response http.ResponseWriter, request *http.Request) { + _, hub, _, _, ok := hubPermissionContext(response, request, normal, types.PermissionSetChannelDescription) + if !ok { + return + } + newDescription := request.FormValue("description") + channelId, err := convertions.StringToUint8(request.FormValue("id")) + if err != nil { + http.Error(response, "invalid channel id", http.StatusBadRequest) + return + } + + hub.Mu.Lock() + channel := hub.Channels[channelId] + if channel == nil { + http.Error(response, "no such channel", http.StatusNotFound) + return + } + channel.Description = newDescription + hub.Mu.Unlock() + + response.WriteHeader(http.StatusAccepted) +}