some fixes for attachments and edits and previews
Ted Unangst tedu@tedunangst.com
Sat, 26 Aug 2023 18:09:21 -0400
2 files changed,
22 insertions(+),
9 deletions(-)
M
views/honkform.html
→
views/honkform.html
@@ -9,8 +9,7 @@ <p>
<details> <summary>more options</summary> <p> -<label class=button id="donker">attach: <input type="file" multiple name="donk"><span>{{ .SavedFile }}</span></label> -<input type="hidden" id="saveddonkxid" name="donkxid" value="{{ .SavedFile }}"> +<label class=button id="donker">attach: <input type="file" multiple name="donk"><span>{{ .SavedFile }}</span></label><input type="hidden" id="saveddonkxid" name="donkxid" value="{{ .SavedFile }}"> <p id="donkdescriptor"><label for=donkdesc>description:</label><br> <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomplete=off> {{ with .SavedPlace }}
M
web.go
→
web.go
@@ -1569,11 +1569,15 @@ if tm.Duration != 0 {
templinfo["Duration"] = tm.Duration } } - templinfo["ServerMessage"] = "honk edit 2" + templinfo["ServerMessage"] = "honk edit" templinfo["IsPreview"] = true templinfo["UpdateXID"] = honk.XID if len(honk.Donks) > 0 { - templinfo["SavedFile"] = honk.Donks[0].XID + var savedfiles []string + for _, d := range honk.Donks { + savedfiles = append(savedfiles, fmt.Sprintf("%s:%d", d.XID, d.FileID)) + } + templinfo["SavedFile"] = strings.Join(savedfiles, ",") } err := readviews.Execute(w, "honkpage.html", templinfo) if err != nil {@@ -1618,7 +1622,10 @@ if !strings.HasPrefix(strings.ToLower(r.Header.Get("Content-Type")), "multipart/form-data") {
return nil, nil } var donks []*Donk - for _, hdr := range r.MultipartForm.File["donk"] { + for i, hdr := range r.MultipartForm.File["donk"] { + if i > 16 { + break + } donk, err := formtodonk(w, r, hdr) if err != nil { return nil, err@@ -1825,7 +1832,7 @@ }
honk.Public = loudandproud(honk.Audience) honk.Convoy = convoy - donkxid := r.FormValue("donkxid") + donkxid := strings.Join(r.Form["donkxid"], ",") if donkxid == "" { donks, err := submitdonk(w, r) if err != nil && err != http.ErrMissingFile {@@ -1833,11 +1840,18 @@ return nil
} if len(donks) > 0 { honk.Donks = append(honk.Donks, donks...) - d := donks[0] - donkxid = fmt.Sprintf("%s:%d", d.XID, d.FileID) + var xids []string + for _, d := range honk.Donks { + xids = append(xids, fmt.Sprintf("%s:%d", d.XID, d.FileID)) + } + donkxid = strings.Join(xids, ",") } } else { - for _, xid := range r.Form["donkxid"] { + xids := strings.Split(donkxid, ",") + for i, xid := range xids { + if i > 16 { + break + } p := strings.Split(xid, ":") xid = p[0] url := fmt.Sprintf("https://%s/d/%s", serverName, xid)