add channel set desc
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user