1
0

Properly form a download URL.

This commit is contained in:
Alexander Andreev 2022-02-08 19:21:44 +04:00
parent c884fe8225
commit 4a5f54ee70
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -14,6 +14,7 @@ import (
"io"
"io/fs"
"net/http"
"net/url"
"os"
"path"
"strings"
@ -174,16 +175,18 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
}
downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)
downloadURLParsed, _ := url.Parse(downloadURL)
if strings.Contains(r.UserAgent(), "curl") {
_, scheme := utils.NetworkType(r.Host)
w.Write([]byte(path.Join(scheme, "://", r.Host, downloadURL) + "\r\n"))
downloadURL = fmt.Sprint(scheme, "://", r.Host, downloadURLParsed, "\r\n")
w.Write([]byte(downloadURL))
return
}
if err := compiledTemplates["uploaded"].Execute(w, &UploadedData{
MainSite: utils.MainSite(r.Host),
DownloadURL: downloadURL,
DownloadURL: downloadURLParsed.String(),
KeepForHours: h.conf.Uploads.Limits.KeepForHours,
}); err != nil {
w.WriteHeader(http.StatusInternalServerError)