Update upload.go

This commit is contained in:
ZizzyDizzyMC 2021-02-09 22:44:04 -05:00
parent de6b3bc23f
commit f87914a2a2
1 changed files with 5 additions and 6 deletions

View File

@ -92,7 +92,7 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq.expiry = parseExpiry(r.PostFormValue("expires")) upReq.expiry = parseExpiry(r.PostFormValue("expires"))
upReq.accessKey = r.PostFormValue(accessKeyParamName) upReq.accessKey = r.PostFormValue(accessKeyParamName)
upReq.srcIp = r.Header.get("X-Forwarded-For")
if r.PostFormValue("randomize") == "true" { if r.PostFormValue("randomize") == "true" {
upReq.randomBarename = true upReq.randomBarename = true
} }
@ -131,7 +131,7 @@ func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close() defer r.Body.Close()
upReq.filename = c.URLParams["name"] upReq.filename = c.URLParams["name"]
upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize) upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize)
upReq.srcIp = r.Header.get("X-Forwarded-For")
upload, err := processUpload(upReq) upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) { if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -203,7 +203,7 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
upReq.accessKey = r.FormValue(accessKeyParamName) upReq.accessKey = r.FormValue(accessKeyParamName)
upReq.randomBarename = r.FormValue("randomize") == "yes" upReq.randomBarename = r.FormValue("randomize") == "yes"
upReq.expiry = parseExpiry(r.FormValue("expiry")) upReq.expiry = parseExpiry(r.FormValue("expiry"))
upReq.srcIp = r.Header.get("X-Forwarded-For")
upload, err := processUpload(upReq) upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) { if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -334,8 +334,7 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
if upReq.deleteKey == "" { if upReq.deleteKey == "" {
upReq.deleteKey = uniuri.NewLen(30) upReq.deleteKey = uniuri.NewLen(30)
} }
var srcIp = r.Header.get("X-Forwarded-For") upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey, upReq.srcIp)
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey, srcIp)
if err != nil { if err != nil {
return upload, err return upload, err
} }