|
|
@@ -5,6 +5,7 @@ import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"io" |
|
|
"io" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"strings" |
|
|
"sync" |
|
|
"sync" |
|
|
|
|
|
|
|
|
"github.com/jan/fm-rds-tx/internal/audio" |
|
|
"github.com/jan/fm-rds-tx/internal/audio" |
|
|
@@ -49,6 +50,8 @@ type Server struct { |
|
|
streamSrc *audio.StreamSource // optional, for live audio ingest |
|
|
streamSrc *audio.StreamSource // optional, for live audio ingest |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const maxConfigBodyBytes = 64 << 10 // 64 KiB |
|
|
|
|
|
|
|
|
type ConfigPatch struct { |
|
|
type ConfigPatch struct { |
|
|
FrequencyMHz *float64 `json:"frequencyMHz,omitempty"` |
|
|
FrequencyMHz *float64 `json:"frequencyMHz,omitempty"` |
|
|
OutputDrive *float64 `json:"outputDrive,omitempty"` |
|
|
OutputDrive *float64 `json:"outputDrive,omitempty"` |
|
|
@@ -296,9 +299,14 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) { |
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
_ = json.NewEncoder(w).Encode(cfg) |
|
|
_ = json.NewEncoder(w).Encode(cfg) |
|
|
case http.MethodPost: |
|
|
case http.MethodPost: |
|
|
|
|
|
r.Body = http.MaxBytesReader(w, r.Body, maxConfigBodyBytes) |
|
|
var patch ConfigPatch |
|
|
var patch ConfigPatch |
|
|
if err := json.NewDecoder(r.Body).Decode(&patch); err != nil { |
|
|
if err := json.NewDecoder(r.Body).Decode(&patch); err != nil { |
|
|
http.Error(w, err.Error(), http.StatusBadRequest) |
|
|
|
|
|
|
|
|
statusCode := http.StatusBadRequest |
|
|
|
|
|
if strings.Contains(err.Error(), "http: request body too large") { |
|
|
|
|
|
statusCode = http.StatusRequestEntityTooLarge |
|
|
|
|
|
} |
|
|
|
|
|
http.Error(w, err.Error(), statusCode) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|