MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiV1CreateAudio

Function apiV1CreateAudio

internal/web/api_v1_audio.go:32–77  ·  view source on GitHub ↗

POST /admin/api/v1/audio Body: {"identifier": "my-sound", "description": "...", "filepath": "...", "volume": 80, "tags": ["combat"]} Creates a new sound entry. Returns 409 if the identifier already exists.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

30// Body: {"identifier": "my-sound", "description": "...", "filepath": "...", "volume": 80, "tags": ["combat"]}
31// Creates a new sound entry. Returns 409 if the identifier already exists.
32func apiV1CreateAudio(w http.ResponseWriter, r *http.Request) {
33 var body struct {
34 Identifier string `json:"identifier"`
35 Description string `json:"description"`
36 FilePath string `json:"filepath"`
37 Volume int `json:"volume"`
38 Tags []string `json:"tags"`
39 }
40 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
41 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
42 return
43 }
44
45 body.Identifier = strings.TrimSpace(body.Identifier)
46 if body.Identifier == "" {
47 writeAPIError(w, http.StatusBadRequest, "identifier is required")
48 return
49 }
50
51 current := audio.GetAllAudio()
52 if _, exists := current[body.Identifier]; exists {
53 writeAPIError(w, http.StatusConflict, "identifier already exists: "+body.Identifier)
54 return
55 }
56
57 current[body.Identifier] = audio.AudioConfig{
58 Description: body.Description,
59 FilePath: body.FilePath,
60 Volume: body.Volume,
61 Tags: body.Tags,
62 }
63
64 if err := audio.SaveAudio(current); err != nil {
65 writeAPIError(w, http.StatusInternalServerError, err.Error())
66 return
67 }
68
69 writeJSON(w, http.StatusOK, APIResponse[audioAPIResponse]{
70 Success: true,
71 Data: audioAPIResponse{
72 Sounds: audio.GetAllAudio(),
73 Music: audio.GetMusicFiles(),
74 SoundFiles: audio.GetSoundFiles(),
75 },
76 })
77}
78
79// PATCH /admin/api/v1/audio
80// Body: {"identifier": {"description":"...","filepath":"...","volume":80}, ...}

Callers

nothing calls this directly

Calls 6

GetAllAudioFunction · 0.92
SaveAudioFunction · 0.92
GetMusicFilesFunction · 0.92
GetSoundFilesFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected