mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-10 07:26:35 +08:00
fix: Fixed logging errors for uploaded files (#9204)
This commit is contained in:
parent
2edddaf487
commit
725786d6aa
2 changed files with 41 additions and 4 deletions
|
@ -1672,12 +1672,13 @@
|
||||||
},
|
},
|
||||||
"/files/upload": {
|
"/files/upload": {
|
||||||
"bodyKeys": [
|
"bodyKeys": [
|
||||||
"path"
|
"path",
|
||||||
|
"file"
|
||||||
],
|
],
|
||||||
"paramKeys": [],
|
"paramKeys": [],
|
||||||
"beforeFunctions": [],
|
"beforeFunctions": [],
|
||||||
"formatZH": "上传文件[path]",
|
"formatZH": "上传文件[path]/[file]",
|
||||||
"formatEN": "Uploadfile[path]"
|
"formatEN": "Uploadfile[path]/[file]"
|
||||||
},
|
},
|
||||||
"/files/wget": {
|
"/files/wget": {
|
||||||
"bodyKeys": [
|
"bodyKeys": [
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
@ -65,7 +67,11 @@ func OperationLog() gin.HandlerFunc {
|
||||||
c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||||
}
|
}
|
||||||
bodyMap := make(map[string]interface{})
|
bodyMap := make(map[string]interface{})
|
||||||
|
if strings.Contains(c.Request.Header.Get("Content-Type"), "multipart/form-data") {
|
||||||
|
bodyMap, _ = parseMultipart(body, c.Request.Header.Get("Content-Type"))
|
||||||
|
} else {
|
||||||
_ = json.Unmarshal(body, &bodyMap)
|
_ = json.Unmarshal(body, &bodyMap)
|
||||||
|
}
|
||||||
for _, key := range operationDic.BodyKeys {
|
for _, key := range operationDic.BodyKeys {
|
||||||
if _, ok := bodyMap[key]; ok {
|
if _, ok := bodyMap[key]; ok {
|
||||||
formatMap[key] = bodyMap[key]
|
formatMap[key] = bodyMap[key]
|
||||||
|
@ -247,3 +253,33 @@ func replaceStr(val string, rep ...string) string {
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMultipart(formData []byte, contentType string) (map[string]interface{}, error) {
|
||||||
|
d, params, err := mime.ParseMediaType(contentType)
|
||||||
|
if err != nil || d != "multipart/form-data" {
|
||||||
|
return nil, http.ErrNotMultipart
|
||||||
|
}
|
||||||
|
boundary, ok := params["boundary"]
|
||||||
|
if !ok {
|
||||||
|
return nil, http.ErrMissingBoundary
|
||||||
|
}
|
||||||
|
reader := multipart.NewReader(bytes.NewReader(formData), boundary)
|
||||||
|
ret := make(map[string]interface{})
|
||||||
|
|
||||||
|
f, err := reader.ReadForm(32 << 20)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range f.Value {
|
||||||
|
if len(v) > 0 {
|
||||||
|
ret[k] = v[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range f.File {
|
||||||
|
if len(v) > 0 {
|
||||||
|
ret[k] = v[0].Filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue