Update upload.go

This commit is contained in:
ZizzyDizzyMC 2021-02-21 21:14:31 -05:00
parent 17441020c2
commit 0156fdb15b
1 changed files with 15 additions and 12 deletions

View File

@ -135,6 +135,11 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) { func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq := UploadRequest{} upReq := UploadRequest{}
uploadHeaderProcess(r, &upReq) uploadHeaderProcess(r, &upReq)
defer r.Body.Close()
upReq.filename = c.URLParams["name"]
upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize)
upReq.srcIp = r.Header.Get("X-Forwarded-For")
if len(r.Header.Get("Content-Length")) > 0 { if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64) i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
@ -144,11 +149,7 @@ func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
} }
} }
} }
defer r.Body.Close()
upReq.filename = c.URLParams["name"]
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")) {
@ -213,6 +214,15 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
oopsHandler(c, w, r, RespAUTO, "Could not retrieve URL") oopsHandler(c, w, r, RespAUTO, "Could not retrieve URL")
return return
} }
upReq.filename = filepath.Base(grabUrl.Path)
upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize)
upReq.deleteKey = r.FormValue("deletekey")
upReq.accessKey = r.FormValue(accessKeyParamName)
upReq.randomBarename = r.FormValue("randomize") == "yes"
upReq.expiry = parseExpiry(r.FormValue("expiry"))
upReq.srcIp = r.Header.Get("X-Forwarded-For")
if len(r.Header.Get("Content-Length")) > 0 { if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64) i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err == nil { if err == nil {
@ -222,13 +232,6 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
} }
} }
upReq.filename = filepath.Base(grabUrl.Path)
upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize)
upReq.deleteKey = r.FormValue("deletekey")
upReq.accessKey = r.FormValue(accessKeyParamName)
upReq.randomBarename = r.FormValue("randomize") == "yes"
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")) {