From 96119efa416cefde8dc3bce1a30eeface3307aa2 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 1 Jul 2024 22:17:10 -0700 Subject: [PATCH] chore(api): start moving some types to the codegen types --- webserver/handlers/admin/appearance.go | 9 +++------ webserver/handlers/admin/chat.go | 13 +++++++------ webserver/handlers/admin/emoji.go | 12 ++++-------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/webserver/handlers/admin/appearance.go b/webserver/handlers/admin/appearance.go index 6d920a903..0312abe47 100644 --- a/webserver/handlers/admin/appearance.go +++ b/webserver/handlers/admin/appearance.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/owncast/owncast/core/data" + "github.com/owncast/owncast/webserver/handlers/generated" webutils "github.com/owncast/owncast/webserver/utils" ) @@ -14,19 +15,15 @@ func SetCustomColorVariableValues(w http.ResponseWriter, r *http.Request) { return } - type request struct { - Value map[string]string `json:"value"` - } - decoder := json.NewDecoder(r.Body) - var values request + var values generated.SetCustomColorVariableValuesJSONBody if err := decoder.Decode(&values); err != nil { webutils.WriteSimpleResponse(w, false, "unable to update appearance variable values") return } - if err := data.SetCustomColorVariableValues(values.Value); err != nil { + if err := data.SetCustomColorVariableValues(*values.Value); err != nil { webutils.WriteSimpleResponse(w, false, err.Error()) return } diff --git a/webserver/handlers/admin/chat.go b/webserver/handlers/admin/chat.go index a4f536c97..cf2e7b4d1 100644 --- a/webserver/handlers/admin/chat.go +++ b/webserver/handlers/admin/chat.go @@ -15,6 +15,7 @@ import ( "github.com/owncast/owncast/models" "github.com/owncast/owncast/persistence/userrepository" "github.com/owncast/owncast/utils" + "github.com/owncast/owncast/webserver/handlers/generated" webutils "github.com/owncast/owncast/webserver/utils" log "github.com/sirupsen/logrus" ) @@ -26,10 +27,10 @@ func ExternalUpdateMessageVisibility(integration models.ExternalAPIUser, w http. // UpdateMessageVisibility updates an array of message IDs to have the same visiblity. func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) { - type messageVisibilityUpdateRequest struct { - IDArray []string `json:"idArray"` - Visible bool `json:"visible"` - } + // type messageVisibilityUpdateRequest struct { + // IDArray []string `json:"idArray"` + // Visible bool `json:"visible"` + // } if r.Method != http.MethodPost { // nolint:goconst @@ -38,7 +39,7 @@ func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) { } decoder := json.NewDecoder(r.Body) - var request messageVisibilityUpdateRequest + var request generated.MessageVisibilityUpdate if err := decoder.Decode(&request); err != nil { log.Errorln(err) @@ -46,7 +47,7 @@ func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) { return } - if err := chat.SetMessagesVisibility(request.IDArray, request.Visible); err != nil { + if err := chat.SetMessagesVisibility(*request.IdArray, *request.Visible); err != nil { webutils.WriteSimpleResponse(w, false, err.Error()) return } diff --git a/webserver/handlers/admin/emoji.go b/webserver/handlers/admin/emoji.go index 2c9f7e454..f310953bf 100644 --- a/webserver/handlers/admin/emoji.go +++ b/webserver/handlers/admin/emoji.go @@ -9,6 +9,7 @@ import ( "github.com/owncast/owncast/config" "github.com/owncast/owncast/utils" + "github.com/owncast/owncast/webserver/handlers/generated" webutils "github.com/owncast/owncast/webserver/utils" ) @@ -18,26 +19,21 @@ func UploadCustomEmoji(w http.ResponseWriter, r *http.Request) { return } - type postEmoji struct { - Name string `json:"name"` - Data string `json:"data"` - } - - emoji := new(postEmoji) + emoji := new(generated.UploadCustomEmojiJSONBody) if err := json.NewDecoder(r.Body).Decode(emoji); err != nil { webutils.WriteSimpleResponse(w, false, err.Error()) return } - bytes, _, err := utils.DecodeBase64Image(emoji.Data) + bytes, _, err := utils.DecodeBase64Image(*emoji.Data) if err != nil { webutils.WriteSimpleResponse(w, false, err.Error()) return } // Prevent path traversal attacks - emojiFileName := filepath.Base(emoji.Name) + emojiFileName := filepath.Base(*emoji.Name) targetPath := filepath.Join(config.CustomEmojiPath, emojiFileName) err = os.MkdirAll(config.CustomEmojiPath, 0o700)