This commit is contained in:
@@ -196,7 +196,6 @@ func (s *Server) Handler() http.Handler {
|
||||
r.Post("/submit", s.handleSubmit)
|
||||
r.Get("/questions/{id}", s.handleQuestion)
|
||||
r.Post("/questions/{id}/vote", s.handleVote)
|
||||
r.Post("/questions/{id}/answer", s.handleAnswer)
|
||||
r.Post("/questions/{id}/hide", s.handleHide)
|
||||
r.Post("/posts", s.handleCreatePost)
|
||||
r.Post("/posts/{id}/edit", s.handleEditPost)
|
||||
@@ -478,48 +477,6 @@ func (s *Server) renderLeaderboard(w http.ResponseWriter, r *http.Request, date
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleAnswer(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.requireCSRF(w, r) {
|
||||
return
|
||||
}
|
||||
u := currentUser(r)
|
||||
if !u.Admin() {
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
id := chi.URLParam(r, "id")
|
||||
body := strings.TrimSpace(r.PostFormValue("body"))
|
||||
if body == "" {
|
||||
http.Error(w, "answer required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(body) > 12000 {
|
||||
body = truncateRunes(body, 12000)
|
||||
}
|
||||
root, err := s.store.GetPost(r.Context(), id)
|
||||
if err != nil || root.ParentID != nil || root.PostState == store.PostStateHidden {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
reply := &store.Post{
|
||||
ParentID: &root.ID,
|
||||
AuthorID: u.ID,
|
||||
Body: body,
|
||||
}
|
||||
if err := s.store.CreatePost(r.Context(), reply); err != nil {
|
||||
http.Error(w, "could not save answer", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
s.notifyPostReply(root, root, reply, u)
|
||||
location := "/questions/" + url.PathEscape(id) + "#post-" + url.PathEscape(reply.ID)
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("HX-Redirect", location)
|
||||
w.WriteHeader(http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, location, http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) handleHide(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.requireCSRF(w, r) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user