diff --git a/web/main.go b/web/main.go index 4fedeb7..cddcd5d 100644 --- a/web/main.go +++ b/web/main.go @@ -369,22 +369,20 @@ func main() { mediaPath := "" thumbPath := "" - if body == "" { - http.Error(w, "Body is empty", http.StatusBadRequest) - return - } - if len(body) > util.MAX_BODY_LEN { http.Error(w, fmt.Sprintf("Body exceeds %d characters", util.MAX_BODY_LEN), http.StatusBadRequest) return } + fileIsEmpty := false file, header, err := r.FormFile("file") if err != nil { if !errors.Is(err, http.ErrMissingFile) { http.Error(w, "Failed to retrieve file from form", http.StatusBadRequest) log.Printf("FormFile: %v", err) return + } else { + fileIsEmpty = true } } else { defer file.Close() @@ -417,6 +415,11 @@ func main() { thumbPath = savedThumbPath } + if body == "" && fileIsEmpty { + http.Error(w, "No body or file provided", http.StatusBadRequest) + return + } + if err := database.PutPost(db, slug, threadId, body, mediaPath, thumbPath, ipHash); err != nil { http.Error(w, "Failed to create post", http.StatusInternalServerError) log.Printf("PutPost: %v", err) diff --git a/web/views/shared/form.templ b/web/views/shared/form.templ index 6ffc0b7..2adf212 100644 --- a/web/views/shared/form.templ +++ b/web/views/shared/form.templ @@ -40,7 +40,15 @@ templ NewPostForm(board database.Board, endpoint string, isForThread bool) {