Update upload.go

This commit is contained in:
ZizzyDizzyMC 2021-02-21 21:01:07 -05:00
parent 7635abf2dc
commit 17441020c2
1 changed files with 28 additions and 9 deletions

View File

@ -95,6 +95,16 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq.randomBarename = true
}
upReq.srcIp = r.Header.Get("X-Forwarded-For")
if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err == nil {
if i > Config.maxSize {
upReq.size = i
}
}
}
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
@ -126,6 +136,15 @@ func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
upReq := UploadRequest{}
uploadHeaderProcess(r, &upReq)
if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err == nil {
if i > Config.maxSize {
upReq.size = i
}
}
}
defer r.Body.Close()
upReq.filename = c.URLParams["name"]
upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize)
@ -194,6 +213,14 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
oopsHandler(c, w, r, RespAUTO, "Could not retrieve URL")
return
}
if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err == nil {
if i > Config.maxSize {
upReq.size = i
}
}
}
upReq.filename = filepath.Base(grabUrl.Path)
upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize)
@ -228,14 +255,6 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
}
func uploadHeaderProcess(r *http.Request, upReq *UploadRequest) {
if len(r.Header.Get("Content-Length")) > 0 {
i, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
if err == nil {
if i > Config.maxSize {
upReq.size = i
}
}
}
if r.Header.Get("Linx-Randomize") == "yes" {
upReq.randomBarename = true
}