Merge pull request #228 from dutchcoders/ISSUE-221

ISSUE-221
This commit is contained in:
Andrea Spacca 2019-05-18 20:50:12 +02:00 committed by GitHub
commit 46c53c1cab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

2
go.mod
View file

@ -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

2
go.sum
View file

@ -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=

View file

@ -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 = ""
}