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

Function apiV2PutSpellScript

internal/web/api_v2_spells.go:136–159  ·  view source on GitHub ↗

PUT /admin/api/v2/spells/{spellId}/script

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

Source from the content-addressed store, hash-verified

134
135// PUT /admin/api/v2/spells/{spellId}/script
136func apiV2PutSpellScript(w http.ResponseWriter, r *http.Request) {
137 spellId := r.PathValue("spellId")
138 if spells.GetSpell(spellId) == nil {
139 writeAPIError(w, http.StatusNotFound, "spell not found: "+spellId)
140 return
141 }
142
143 var body struct {
144 Script string `json:"script"`
145 }
146 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
147 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
148 return
149 }
150
151 if err := spells.SaveSpellScript(spellId, body.Script); err != nil {
152 writeAPIError(w, http.StatusInternalServerError, err.Error())
153 return
154 }
155
156 scripting.InvalidateSpellVM(spellId)
157
158 writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true})
159}

Callers

nothing calls this directly

Calls 5

GetSpellFunction · 0.92
SaveSpellScriptFunction · 0.92
InvalidateSpellVMFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected