mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 12:18:02 +03:00
chore(api): start moving some types to the codegen types
This commit is contained in:
parent
93c0a20935
commit
96119efa41
3 changed files with 14 additions and 20 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue