1
0

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:
Alexander Andreev 2022-02-08 19:02:37 +04:00
parent 0e46641599
commit c884fe8225
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -16,6 +16,7 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"strings"
"time" "time"
"github.com/Joker/jade" "github.com/Joker/jade"
@ -161,7 +162,9 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
return 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) fHandler.Filename, fSha256, fSaltedHash, fHandler.Size)
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
@ -170,13 +173,14 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusFound) w.WriteHeader(http.StatusFound)
} }
scheme := r.Header.Get("X-Forwarded-Proto")
if scheme == "" {
scheme = "http"
}
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename) 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{ if err := compiledTemplates["uploaded"].Execute(w, &UploadedData{
MainSite: utils.MainSite(r.Host), MainSite: utils.MainSite(r.Host),
DownloadURL: downloadURL, DownloadURL: downloadURL,
@ -209,7 +213,9 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
} }
defer fd.Close() 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) http.ServeContent(w, r, path, stat.ModTime(), fd)
} }