This commit is contained in:
+15
-1
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/alexedwards/scs/v2"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"plumber/internal/blob"
|
||||
"plumber/internal/geo"
|
||||
@@ -182,7 +183,7 @@ func (s *Server) Handler() http.Handler {
|
||||
r.Use(middleware.Recoverer)
|
||||
r.Use(func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, 3<<20)
|
||||
r.Body = http.MaxBytesReader(w, r.Body, requestBodyLimit(r))
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
})
|
||||
@@ -331,6 +332,11 @@ func (s *Server) handleSubmitForm(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) handleSubmit(w http.ResponseWriter, r *http.Request) {
|
||||
cleanup, ok := parsePostMutationForm(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
defer cleanup()
|
||||
if !s.requireCSRF(w, r) {
|
||||
return
|
||||
}
|
||||
@@ -362,12 +368,20 @@ func (s *Server) handleSubmit(w http.ResponseWriter, r *http.Request) {
|
||||
city = truncateRunes(city, 80)
|
||||
}
|
||||
post := &store.Post{
|
||||
ID: uuid.NewString(),
|
||||
AuthorID: u.ID,
|
||||
Title: title,
|
||||
Body: body,
|
||||
City: city,
|
||||
}
|
||||
images, newKeys, err := s.postImagesFromForm(r.Context(), r, post.ID, nil)
|
||||
if err != nil {
|
||||
writePostImageRequestError(w, err)
|
||||
return
|
||||
}
|
||||
post.Images = images
|
||||
if err := s.store.CreatePost(r.Context(), post); err != nil {
|
||||
s.deletePostImageObjects(newKeys)
|
||||
http.Error(w, "could not save question", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user