Allow posting image without body
This commit is contained in:
+8
-5
@@ -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)
|
||||
|
||||
@@ -40,7 +40,15 @@ templ NewPostForm(board database.Board, endpoint string, isForThread bool) {
|
||||
</tr>
|
||||
<tr class="new-post-form-field">
|
||||
<th>Comment</th>
|
||||
<td><textarea id="newPostBody" name="body" required></textarea></td>
|
||||
<td>
|
||||
<textarea
|
||||
id="newPostBody"
|
||||
name="body"
|
||||
if isForThread {
|
||||
required
|
||||
}
|
||||
></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="new-post-form-field">
|
||||
<th>File</th>
|
||||
|
||||
Reference in New Issue
Block a user