PUT /admin/api/v1/rooms/{roomId}/script
(w http.ResponseWriter, r *http.Request)
| 310 | |
| 311 | // PUT /admin/api/v1/rooms/{roomId}/script |
| 312 | func apiV1PutRoomScript(w http.ResponseWriter, r *http.Request) { |
| 313 | roomId, err := strconv.Atoi(r.PathValue("roomId")) |
| 314 | if err != nil { |
| 315 | writeAPIError(w, http.StatusBadRequest, "roomId must be an integer") |
| 316 | return |
| 317 | } |
| 318 | |
| 319 | if rooms.GetRoomForAdmin(roomId) == nil { |
| 320 | writeAPIError(w, http.StatusNotFound, "room not found: "+strconv.Itoa(roomId)) |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | var body struct { |
| 325 | Script string `json:"script"` |
| 326 | } |
| 327 | if err := json.NewDecoder(r.Body).Decode(&body); err != nil { |
| 328 | writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error()) |
| 329 | return |
| 330 | } |
| 331 | |
| 332 | if err := rooms.SaveRoomScript(roomId, body.Script); err != nil { |
| 333 | writeAPIError(w, http.StatusInternalServerError, err.Error()) |
| 334 | return |
| 335 | } |
| 336 | |
| 337 | scripting.InvalidateRoomVM(roomId) |
| 338 | |
| 339 | writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true}) |
| 340 | } |
| 341 | |
| 342 | // GET /admin/api/v1/rooms/{roomId}/instance |
| 343 | func apiV1GetRoomInstance(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected