Go web application for filling USB drives with media files. Runs in Docker on Unraid with /media, /mnt/usb, /config volumes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
878 B
Go
42 lines
878 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"jukebox_maker/internal/config"
|
|
)
|
|
|
|
var cfgMu sync.Mutex
|
|
|
|
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
|
cfgMu.Lock()
|
|
cfg := *s.deps.Config
|
|
cfgMu.Unlock()
|
|
jsonOK(w, cfg)
|
|
}
|
|
|
|
func (s *Server) handlePutConfig(w http.ResponseWriter, r *http.Request) {
|
|
var incoming config.Config
|
|
if err := json.NewDecoder(r.Body).Decode(&incoming); err != nil {
|
|
jsonErr(w, http.StatusBadRequest, "invalid JSON: "+err.Error())
|
|
return
|
|
}
|
|
if err := incoming.Validate(); err != nil {
|
|
jsonErr(w, http.StatusUnprocessableEntity, err.Error())
|
|
return
|
|
}
|
|
|
|
cfgMu.Lock()
|
|
*s.deps.Config = incoming
|
|
cfgMu.Unlock()
|
|
|
|
if err := config.Save(s.deps.ConfigPath, s.deps.Config); err != nil {
|
|
jsonErr(w, http.StatusInternalServerError, "failed to save config: "+err.Error())
|
|
return
|
|
}
|
|
|
|
jsonOK(w, incoming)
|
|
}
|