diff options
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index 02428f3..55e2682 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -217,6 +217,10 @@ var ( wormholeTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(wormholeTemplateString)).Lookup("outline") ) +type wormholeTemplateArgs struct { + Err string +} + func makeHole() string { const nWords = 10 buf := make([]byte, 2*nWords) @@ -306,7 +310,7 @@ func readHoleFile(w http.ResponseWriter, hole string) error { } func wormhole(w http.ResponseWriter, r *http.Request) { - if err := wormholeTemplate.Execute(w, nil); err != nil { + if err := wormholeTemplate.Execute(w, wormholeTemplateArgs{}); err != nil { log.Printf("Warning: wormhole: %s", err) } } @@ -333,7 +337,7 @@ func wormholeUpload(w http.ResponseWriter, r *http.Request) { if err != nil { break } - if part.FormName() != "file" { + if part.FormName() != "file" || part.FileName() == "" { continue } hole, err := writeHoleFile(part) @@ -351,7 +355,10 @@ func wormholeUpload(w http.ResponseWriter, r *http.Request) { } return } - http.Error(w, "file not found", http.StatusBadRequest) + w.WriteHeader(http.StatusBadRequest) + if err := wormholeTemplate.Execute(w, wormholeTemplateArgs{Err: "don't forget to pick a file"}); err != nil { + log.Printf("Warning: wormholeTemplate: %s", err) + } } func wormholeDownload(w http.ResponseWriter, r *http.Request) { |
