]> Sergey Matveev's repositories - uploader.git/commitdiff
Ability to leave comment to uploaded file
authorSergey Matveev <stargrave@stargrave.org>
Thu, 30 May 2019 17:53:13 +0000 (20:53 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 30 May 2019 17:58:14 +0000 (20:58 +0300)
README
src/uploader/main.go

diff --git a/README b/README
index 823492a49f8895b01a55c1ec6d3b0b1b2b8fad4b..5d674a948daaca55439908757fb05ecb3b281f88 100644 (file)
--- a/README
+++ b/README
@@ -6,6 +6,8 @@ You can upload files with curl:
 
     curl -F fileupload=@somedata.tar.gpg http://localhost:8086/upload/
 
+    curl -F fileupload=@somedata.tar.gpg -F comment="optional comment" http://localhost:8086/upload/
+
 You can verify integrity locally:
 
     b2sum -a blake2b somedata.tar.gpg
index e2154cdc57df52e83648cc9a4fb5cbca0dabe083..c3efd614da06491b530624e2a3dc29456ca7a14d 100644 (file)
@@ -23,15 +23,19 @@ import (
 )
 
 const (
-       WriteBufSize  = 1 << 20
-       FileFieldName = "fileupload"
+       WriteBufSize     = 1 << 20
+       FileFieldName    = "fileupload"
+       CommentFieldName = "comment"
 )
 
 var (
        Index = template.Must(template.New("index").Parse(`<html>
 <head><title>Upload</title></head><body>
 <form enctype="multipart/form-data" action="/upload/" method="post">
-<input type="file" name="{{.}}" /><input type="submit" />
+<input type="file" name="{{.}}" /><br/>
+<label for="comment">Optional comment:</label>
+<textarea name="comment" cols="80" rows="25" name="comment"></textarea><br/>
+<input type="submit" />
 </form></body></html>`))
 )
 
@@ -88,6 +92,16 @@ func upload(w http.ResponseWriter, r *http.Request) {
        }
        fmt.Fprintf(w, "Timestamp: %s\nBytes: %d\nBLAKE2b: %s\n", fn, n, sum)
        log.Println(r.RemoteAddr, fn, p.FileName(), n, sum)
+       p, err = mr.NextPart()
+       if err != nil || p.FormName() != CommentFieldName {
+               return
+       }
+       comment, err := ioutil.ReadAll(p)
+       if err != nil || len(comment) == 0 {
+               return
+       }
+       ioutil.WriteFile(fn+".txt", comment, os.FileMode(0600))
+       go notify(fn, n, string(comment))
 }
 
 func main() {