package api import ( "net/http" "regexp" ) func (r *Router) handleClearPortLogs(w http.ResponseWriter, req *http.Request) { ctx, ok := r.authorizeCommand(w, req, commandSpec{Action: "log.port.clear", Target: "logs", Permission: "log.clear"}) if !ok { return } var body struct { Channel string `json:"channel"` Confirmation string `json:"confirmation"` } if ok, _ := decodeJSONBody(w, req, &body, false); !ok { return } if !regexp.MustCompile(`^CH(?:0[1-9]|[1-3][0-9]|4[0-8])$`).MatchString(body.Channel) || body.Confirmation != body.Channel { writeError(w, http.StatusBadRequest, "validation_failed", "select one port CH01 through CH48 and confirm its exact channel") return } result, err := r.store.ClearPortLogs(ctx, body.Channel) writeResult(w, result, err) }