| 1 | package serve |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "io" |
| 6 | "net/http" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | func (s *Server) compact(w http.ResponseWriter, r *http.Request) { |
| 11 | var body struct { |
| 12 | Instructions string `json:"instructions"` |
| 13 | } |
| 14 | if err := json.NewDecoder(r.Body).Decode(&body); err != nil && err != io.EOF { |
| 15 | http.Error(w, "bad body", http.StatusBadRequest) |
| 16 | return |
| 17 | } |
| 18 | if err := s.ctl().Compact(r.Context(), strings.TrimSpace(body.Instructions)); err != nil { |
| 19 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 20 | return |
| 21 | } |
| 22 | w.WriteHeader(http.StatusNoContent) |
| 23 | } |
| 24 |