Let's check if client is curl and return just a link.
And NetworkType() returns a scheme as well now.
This commit is contained in:
parent
0e46641599
commit
c884fe8225
@ -16,6 +16,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Joker/jade"
|
||||
@ -161,7 +162,9 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
h.logUpload.Printf("| %s | %s | %s | SHA256 %s | %s | %d", r.RemoteAddr, utils.NetworkType(r.Host),
|
||||
netTyp, _ := utils.NetworkType(r.Host)
|
||||
|
||||
h.logUpload.Printf("| %s | %s | %s | SHA256 %s | %s | %d", r.RemoteAddr, netTyp,
|
||||
fHandler.Filename, fSha256, fSaltedHash, fHandler.Size)
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
@ -170,13 +173,14 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusFound)
|
||||
}
|
||||
|
||||
scheme := r.Header.Get("X-Forwarded-Proto")
|
||||
if scheme == "" {
|
||||
scheme = "http"
|
||||
}
|
||||
|
||||
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)
|
||||
|
||||
if strings.Contains(r.UserAgent(), "curl") {
|
||||
_, scheme := utils.NetworkType(r.Host)
|
||||
w.Write([]byte(path.Join(scheme, "://", r.Host, downloadURL) + "\r\n"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := compiledTemplates["uploaded"].Execute(w, &UploadedData{
|
||||
MainSite: utils.MainSite(r.Host),
|
||||
DownloadURL: downloadURL,
|
||||
@ -209,7 +213,9 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
h.logDownload.Printf("| %s | %s | %s | %s", r.RemoteAddr, utils.NetworkType(r.Host), name, saltedHash)
|
||||
netTyp, _ := utils.NetworkType(r.Host)
|
||||
|
||||
h.logDownload.Printf("| %s | %s | %s | %s", r.RemoteAddr, netTyp, name, saltedHash)
|
||||
|
||||
http.ServeContent(w, r, path, stat.ModTime(), fd)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user