Trim space for post bodies
This commit is contained in:
+14
-10
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dominicf2001/comfychan/internal/database"
|
"github.com/dominicf2001/comfychan/internal/database"
|
||||||
@@ -125,6 +126,7 @@ func main() {
|
|||||||
|
|
||||||
// CREATE THREAD
|
// CREATE THREAD
|
||||||
r.Post("/{slug}/threads", func(w http.ResponseWriter, r *http.Request) {
|
r.Post("/{slug}/threads", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
slug := chi.URLParam(r, "slug")
|
||||||
ip := util.GetIP(r)
|
ip := util.GetIP(r)
|
||||||
|
|
||||||
timeRemaining := util.IsOnCooldown(ip, util.ThreadCooldowns, util.THREAD_COOLDOWN)
|
timeRemaining := util.IsOnCooldown(ip, util.ThreadCooldowns, util.THREAD_COOLDOWN)
|
||||||
@@ -135,17 +137,15 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
slug := chi.URLParam(r, "slug")
|
|
||||||
|
|
||||||
subject := r.FormValue("subject")
|
|
||||||
body := r.FormValue("body")
|
|
||||||
|
|
||||||
if err := r.ParseMultipartForm(util.FILE_MEM_LIMIT); err != nil {
|
if err := r.ParseMultipartForm(util.FILE_MEM_LIMIT); err != nil {
|
||||||
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
||||||
log.Printf("ParseMultipartForm: %v", err)
|
log.Printf("ParseMultipartForm: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subject := r.FormValue("subject")
|
||||||
|
body := strings.TrimSpace(r.FormValue("body"))
|
||||||
|
|
||||||
file, header, err := r.FormFile("file")
|
file, header, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to retrive file from form", http.StatusBadRequest)
|
http.Error(w, "Failed to retrive file from form", http.StatusBadRequest)
|
||||||
@@ -170,17 +170,16 @@ func main() {
|
|||||||
|
|
||||||
// CREATE POST
|
// CREATE POST
|
||||||
r.Post("/{slug}/threads/{threadId}", func(w http.ResponseWriter, r *http.Request) {
|
r.Post("/{slug}/threads/{threadId}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
slug := chi.URLParam(r, "slug")
|
||||||
ip := util.GetIP(r)
|
ip := util.GetIP(r)
|
||||||
|
|
||||||
timeRemaining := util.IsOnCooldown(ip, util.PostCooldowns, util.POST_COOLDOWN)
|
timeRemaining := util.IsOnCooldown(ip, util.PostCooldowns, util.POST_COOLDOWN)
|
||||||
if timeRemaining > 0 {
|
if timeRemaining > 0 {
|
||||||
response := fmt.Sprintf("Please wait %.0f seconds.", timeRemaining.Seconds())
|
response := fmt.Sprintf("Please wait %.0f seconds.", timeRemaining.Seconds())
|
||||||
|
|
||||||
http.Error(w, response, http.StatusTooManyRequests)
|
http.Error(w, response, http.StatusTooManyRequests)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
slug := chi.URLParam(r, "slug")
|
|
||||||
threadIdStr := chi.URLParam(r, "threadId")
|
threadIdStr := chi.URLParam(r, "threadId")
|
||||||
threadId, err := strconv.Atoi(threadIdStr)
|
threadId, err := strconv.Atoi(threadIdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -188,15 +187,20 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body := r.FormValue("body")
|
|
||||||
mediaPath := ""
|
|
||||||
|
|
||||||
if err := r.ParseMultipartForm(util.FILE_MEM_LIMIT); err != nil {
|
if err := r.ParseMultipartForm(util.FILE_MEM_LIMIT); err != nil {
|
||||||
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
||||||
log.Printf("ParseMultipartForm: %v", err)
|
log.Printf("ParseMultipartForm: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body := strings.TrimSpace(r.FormValue("body"))
|
||||||
|
mediaPath := ""
|
||||||
|
|
||||||
|
if body == "" {
|
||||||
|
http.Error(w, "Malformed post body", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
file, header, err := r.FormFile("file")
|
file, header, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, http.ErrMissingFile) {
|
if !errors.Is(err, http.ErrMissingFile) {
|
||||||
|
|||||||
Reference in New Issue
Block a user