mirror of
https://github.com/owncast/owncast.git
synced 2024-11-28 11:09:01 +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"
|
"net/http"
|
||||||
|
|
||||||
"github.com/owncast/owncast/core/data"
|
"github.com/owncast/owncast/core/data"
|
||||||
|
"github.com/owncast/owncast/webserver/handlers/generated"
|
||||||
webutils "github.com/owncast/owncast/webserver/utils"
|
webutils "github.com/owncast/owncast/webserver/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,19 +15,15 @@ func SetCustomColorVariableValues(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type request struct {
|
|
||||||
Value map[string]string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
var values request
|
var values generated.SetCustomColorVariableValuesJSONBody
|
||||||
|
|
||||||
if err := decoder.Decode(&values); err != nil {
|
if err := decoder.Decode(&values); err != nil {
|
||||||
webutils.WriteSimpleResponse(w, false, "unable to update appearance variable values")
|
webutils.WriteSimpleResponse(w, false, "unable to update appearance variable values")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := data.SetCustomColorVariableValues(values.Value); err != nil {
|
if err := data.SetCustomColorVariableValues(*values.Value); err != nil {
|
||||||
webutils.WriteSimpleResponse(w, false, err.Error())
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/owncast/owncast/models"
|
"github.com/owncast/owncast/models"
|
||||||
"github.com/owncast/owncast/persistence/userrepository"
|
"github.com/owncast/owncast/persistence/userrepository"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
|
"github.com/owncast/owncast/webserver/handlers/generated"
|
||||||
webutils "github.com/owncast/owncast/webserver/utils"
|
webutils "github.com/owncast/owncast/webserver/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
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.
|
// UpdateMessageVisibility updates an array of message IDs to have the same visiblity.
|
||||||
func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) {
|
func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) {
|
||||||
type messageVisibilityUpdateRequest struct {
|
// type messageVisibilityUpdateRequest struct {
|
||||||
IDArray []string `json:"idArray"`
|
// IDArray []string `json:"idArray"`
|
||||||
Visible bool `json:"visible"`
|
// Visible bool `json:"visible"`
|
||||||
}
|
// }
|
||||||
|
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
// nolint:goconst
|
// nolint:goconst
|
||||||
|
@ -38,7 +39,7 @@ func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
var request messageVisibilityUpdateRequest
|
var request generated.MessageVisibilityUpdate
|
||||||
|
|
||||||
if err := decoder.Decode(&request); err != nil {
|
if err := decoder.Decode(&request); err != nil {
|
||||||
log.Errorln(err)
|
log.Errorln(err)
|
||||||
|
@ -46,7 +47,7 @@ func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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())
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
|
"github.com/owncast/owncast/webserver/handlers/generated"
|
||||||
webutils "github.com/owncast/owncast/webserver/utils"
|
webutils "github.com/owncast/owncast/webserver/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,26 +19,21 @@ func UploadCustomEmoji(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type postEmoji struct {
|
emoji := new(generated.UploadCustomEmojiJSONBody)
|
||||||
Name string `json:"name"`
|
|
||||||
Data string `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
emoji := new(postEmoji)
|
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(emoji); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(emoji); err != nil {
|
||||||
webutils.WriteSimpleResponse(w, false, err.Error())
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, _, err := utils.DecodeBase64Image(emoji.Data)
|
bytes, _, err := utils.DecodeBase64Image(*emoji.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
webutils.WriteSimpleResponse(w, false, err.Error())
|
webutils.WriteSimpleResponse(w, false, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent path traversal attacks
|
// Prevent path traversal attacks
|
||||||
emojiFileName := filepath.Base(emoji.Name)
|
emojiFileName := filepath.Base(*emoji.Name)
|
||||||
targetPath := filepath.Join(config.CustomEmojiPath, emojiFileName)
|
targetPath := filepath.Join(config.CustomEmojiPath, emojiFileName)
|
||||||
|
|
||||||
err = os.MkdirAll(config.CustomEmojiPath, 0o700)
|
err = os.MkdirAll(config.CustomEmojiPath, 0o700)
|
||||||
|
|
Loading…
Reference in a new issue