- +
diff --git a/web.go b/web.go
index 0ec9ccf..dc5d1b2 100644
--- a/web.go
+++ b/web.go
@@ -22,6 +22,7 @@ import (
"html/template"
"io"
notrand "math/rand"
+ "mime/multipart"
"net/http"
"net/url"
"os"
@@ -1612,11 +1613,23 @@ func canedithonk(user *WhatAbout, honk *Honk) bool {
return true
}
-func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
+func submitdonk(w http.ResponseWriter, r *http.Request) ([]*Donk, error) {
if !strings.HasPrefix(strings.ToLower(r.Header.Get("Content-Type")), "multipart/form-data") {
return nil, nil
}
- file, filehdr, err := r.FormFile("donk")
+ var donks []*Donk
+ for _, hdr := range r.MultipartForm.File["donk"] {
+ donk, err := formtodonk(w, r, hdr)
+ if err != nil {
+ return nil, err
+ }
+ donks = append(donks, donk)
+ }
+ return donks, nil
+}
+
+func formtodonk(w http.ResponseWriter, r *http.Request, filehdr *multipart.FileHeader) (*Donk, error) {
+ file, err := filehdr.Open()
if err != nil {
if err == http.ErrMissingFile {
return nil, nil
@@ -1814,12 +1827,13 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
donkxid := r.FormValue("donkxid")
if donkxid == "" {
- d, err := submitdonk(w, r)
+ donks, err := submitdonk(w, r)
if err != nil && err != http.ErrMissingFile {
return nil
}
- if d != nil {
- honk.Donks = append(honk.Donks, d)
+ if len(donks) > 0 {
+ honk.Donks = append(honk.Donks, donks...)
+ d := donks[0]
donkxid = fmt.Sprintf("%s:%d", d.XID, d.FileID)
}
} else {
@@ -1992,12 +2006,12 @@ func submitchonk(w http.ResponseWriter, r *http.Request) {
Noise: noise,
Format: format,
}
- d, err := submitdonk(w, r)
+ donks, err := submitdonk(w, r)
if err != nil && err != http.ErrMissingFile {
return
}
- if d != nil {
- ch.Donks = append(ch.Donks, d)
+ if len(donks) > 0 {
+ ch.Donks = append(ch.Donks, donks...)
}
translatechonk(&ch)
@@ -2505,15 +2519,16 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprintf(w, "%s", h.XID)
case "donk":
- d, err := submitdonk(w, r)
+ donks, err := submitdonk(w, r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
- if d == nil {
+ if len(donks) == 0 {
http.Error(w, "missing donk", http.StatusBadRequest)
return
}
+ d := donks[0]
donkxid := fmt.Sprintf("%s:%d", d.XID, d.FileID)
w.Write([]byte(donkxid))
case "zonkit":