MCPcopy
hub / github.com/wavetermdev/waveterm / handleConfigPost

Method handleConfigPost

tsunami/engine/serverhandlers.go:288–325  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

286}
287
288func (h *httpHandlers) handleConfigPost(w http.ResponseWriter, r *http.Request) {
289 body, err := io.ReadAll(r.Body)
290 if err != nil {
291 http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest)
292 return
293 }
294
295 var configData map[string]any
296 if err := json.Unmarshal(body, &configData); err != nil {
297 http.Error(w, fmt.Sprintf("failed to parse JSON: %v", err), http.StatusBadRequest)
298 return
299 }
300
301 var failedKeys []string
302 for key, value := range configData {
303 atomName := "$config." + key
304 if err := h.Client.Root.SetAtomVal(atomName, value); err != nil {
305 failedKeys = append(failedKeys, key)
306 }
307 }
308
309 w.Header().Set("Content-Type", "application/json")
310
311 var response map[string]any
312 if len(failedKeys) > 0 {
313 response = map[string]any{
314 "error": fmt.Sprintf("Failed to update keys: %s", strings.Join(failedKeys, ", ")),
315 }
316 } else {
317 response = map[string]any{
318 "success": true,
319 }
320 }
321
322 w.WriteHeader(http.StatusOK)
323
324 json.NewEncoder(w).Encode(response)
325}
326
327func (h *httpHandlers) handleSchemas(w http.ResponseWriter, r *http.Request) {
328 defer func() {

Callers 1

handleConfigMethod · 0.95

Calls 6

ReadAllMethod · 0.45
ErrorMethod · 0.45
SetAtomValMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected