From e8ccf543f696b9d84d28ba943e25c1bf9c56109b Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 18 May 2019 14:13:23 +0200 Subject: [PATCH] ISSUE-221 --- go.mod | 2 +- go.sum | 2 ++ server/handlers.go | 23 +++++++++++++++-------- server/server.go | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 9145fef..c9c25c1 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/VojtechVitek/ratelimit v0.0.0-20160722140851-dc172bc0f6d2 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329 - github.com/dutchcoders/transfer.sh-web v0.0.0-20190121065949-e7d393abbb07 + github.com/dutchcoders/transfer.sh-web v0.0.0-20190518121139-cc1ae43f8d69 github.com/elazarl/go-bindata-assetfs v1.0.0 github.com/fatih/color v1.7.0 github.com/garyburd/redigo v1.6.0 // indirect diff --git a/go.sum b/go.sum index 5e87e7d..10caff7 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329 h1:ERqCk github.com/dutchcoders/go-virustotal v0.0.0-20140923143438-24cc8e6fa329/go.mod h1:G5qOfE5bQZ5scycLpB7fYWgN4y3xdfXo+pYWM8z2epY= github.com/dutchcoders/transfer.sh-web v0.0.0-20190121065949-e7d393abbb07 h1:L4PB9nsRpVJqpza1aVwroFcShe/N3wh2QcWVpca53jk= github.com/dutchcoders/transfer.sh-web v0.0.0-20190121065949-e7d393abbb07/go.mod h1:UjR1zlrq/R2Sef7e4q3TeJm4HcbLh4vRzlCEGJP+wLg= +github.com/dutchcoders/transfer.sh-web v0.0.0-20190518121139-cc1ae43f8d69 h1:Eb27agCP67voPNMPDEPrXBp+IEWp4ephgX9B3jfR4Uk= +github.com/dutchcoders/transfer.sh-web v0.0.0-20190518121139-cc1ae43f8d69/go.mod h1:UjR1zlrq/R2Sef7e4q3TeJm4HcbLh4vRzlCEGJP+wLg= github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk= github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= diff --git a/server/handlers.go b/server/handlers.go index 9fbd028..78e3c89 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -63,6 +63,8 @@ import ( "github.com/skip2/go-qrcode" ) +const getPathPart = "get" + var ( htmlTemplates = initHTMLTemplates() textTemplates = initTextTemplates() @@ -146,9 +148,12 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) { templatePath = "download.html" } - resolvedUrl := resolveUrl(r, getURL(r).ResolveReference(r.URL), true) + relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, filename)) + resolvedURL := resolveURL(r, getURL(r).ResolveReference(relativeURL), true) + relativeURLGet, _ := url.Parse(path.Join(s.proxyPath, getPathPart, token, filename)) + resolvedURLGet := resolveURL(r, getURL(r).ResolveReference(relativeURLGet), true) var png []byte - png, err = qrcode.Encode(resolvedUrl, qrcode.High, 150) + png, err = qrcode.Encode(resolvedURL, qrcode.High, 150) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -164,6 +169,7 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) { Content html_template.HTML Filename string Url string + UrlGet string Hostname string WebAddress string ContentLength uint64 @@ -174,7 +180,8 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) { contentType, content, filename, - resolvedUrl, + resolvedURL, + resolvedURLGet, hostname, webAddress, contentLength, @@ -482,14 +489,14 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) { filename = url.QueryEscape(filename) relativeURL, _ := url.Parse(path.Join(s.proxyPath, token, filename)) - deleteUrl, _ := url.Parse(path.Join(s.proxyPath, token, filename, metadata.DeletionToken)) + deleteURL, _ := url.Parse(path.Join(s.proxyPath, token, filename, metadata.DeletionToken)) - w.Header().Set("X-Url-Delete", resolveUrl(r, deleteUrl, true)) + w.Header().Set("X-Url-Delete", resolveURL(r, deleteURL, true)) - fmt.Fprint(w, resolveUrl(r, relativeURL, false)) + fmt.Fprint(w, resolveURL(r, relativeURL, false)) } -func resolveUrl(r *http.Request, u *url.URL, absolutePath bool) string { +func resolveURL(r *http.Request, u *url.URL, absolutePath bool) string { if absolutePath { r.URL.Path = "" } @@ -517,7 +524,7 @@ func resolveWebAddress(r *http.Request, proxyPath string) string { var webAddress string if len(proxyPath) == 0 { - webAddress = fmt.Sprintf("%s://%s/", + webAddress = fmt.Sprintf("%s://%s/", url.ResolveReference(url).Scheme, url.ResolveReference(url).Host) } else { diff --git a/server/server.go b/server/server.go index 6971604..16c3197 100644 --- a/server/server.go +++ b/server/server.go @@ -269,7 +269,7 @@ type Server struct { tempPath string webPath string - proxyPath string + proxyPath string gaKey string userVoiceKey string