DustyP 9 months ago
parent 1cda34fe93
commit 9eae310b94

@ -12,8 +12,8 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"log/slog"
"math/big"
@ -1815,27 +1815,33 @@ func (s *Server) handleRerunHeat() http.HandlerFunc {
}
}
func parseRequestBody(r *http.Request) (string, error) {
body, err := io.ReadAll(r.Body)
if err != nil {
return "", err
}
return string(body), nil
}
// handleSetRacingGroup sets the currently racing group
func (s *Server) handleSetRacingGroup() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
text, err := parseRequestBody(r)
if err != nil {
http.Error(w, "Failed to read request body", http.StatusBadRequest)
s.logger.Error("Failed to parse request body", "error", err)
http.Error(w, "Failed to parse request body", http.StatusBadRequest)
return
}
defer r.Body.Close()
// Process the plain text body
text := string(body)
s.logger.Info("Set racing group request", "text", text)
// Parse request body
var request struct {
GroupID int64 `json:"group_id"`
}
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
request.GroupID, err = strconv.ParseInt(strings.Split(text, "=")[1], 10, 64)
if err != nil {
s.logger.Error("Failed to parse group ID", "error", err)
http.Error(w, "Failed to parse group ID", http.StatusBadRequest)
return
}

Loading…
Cancel
Save