diff options
Diffstat (limited to 'controller/file.go')
| -rw-r--r-- | controller/file.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/controller/file.go b/controller/file.go index 53121d5..7aed104 100644 --- a/controller/file.go +++ b/controller/file.go @@ -1,12 +1,17 @@ package controller import ( + "encoding/base64" "fmt" + "html/template" "io" + "log" "net/http" + "net/url" "time" "drop.janw.name/storage" + qrcode "github.com/skip2/go-qrcode" ) const MAX_FILESIZE = (1 << 19) * 100 @@ -44,10 +49,26 @@ func (app App) FilePost(res http.ResponseWriter, req *http.Request) { panic(err) } + log.Println("received new file:", key) + + downloadURL := fmt.Sprintf("%s/%s", app.config.Http.BaseAddress, key) + qrcodePng, err := qrcode.Encode(downloadURL, qrcode.Medium, 256) + + if err != nil { + panic(err) + } + + qrcodeDataUrl := fmt.Sprintf( + "data:image/png;base64,%s", + url.QueryEscape(base64.StdEncoding.WithPadding('=').EncodeToString(qrcodePng)), + ) + app.tmpl.ExecuteTemplate(res, "uploaded", struct { DownloadURL string + QRCode template.URL }{ - DownloadURL: fmt.Sprintf("%s/%s", app.config.Http.BaseAddress, key), + DownloadURL: downloadURL, + QRCode: template.URL(qrcodeDataUrl), }) } @@ -75,5 +96,7 @@ func (app App) FileGet(res http.ResponseWriter, req *http.Request) { if _, err := res.Write(file.Data); err != nil { panic(err) + } else { + log.Println("served file:", fileId, file.Filename) } } |
