1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 00:09:16 +08:00

fix: 解决上传文件根目录报错的BUG

This commit is contained in:
zhengkunwang223 2022-12-16 16:43:07 +08:00 committed by zhengkunwang223
parent 7e9231a527
commit 587c3df06a
3 changed files with 35 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/buserr"
"io/ioutil"
"net/http"
"os"
@ -171,7 +172,7 @@ func (b *BaseApi) UploadFiles(c *gin.Context) {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error paths in request"))
return
}
dir := paths[0][:strings.LastIndex(paths[0], "/")]
dir := path.Dir(paths[0])
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
if err != nil {
@ -181,15 +182,21 @@ func (b *BaseApi) UploadFiles(c *gin.Context) {
}
}
success := 0
failures := make(buserr.MultiErr)
for _, file := range files {
err := c.SaveUploadedFile(file, path.Join(paths[0], file.Filename))
if err != nil {
global.LOG.Errorf("upload [%s] file failed, err: %v", file.Filename, err)
if err := c.SaveUploadedFile(file, path.Join(paths[0], file.Filename)); err != nil {
e := fmt.Errorf("upload [%s] file failed, err: %v", file.Filename, err)
failures[file.Filename] = e
global.LOG.Error(e)
continue
}
success++
}
helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success))
if success == 0 {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, failures)
} else {
helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success))
}
}
func (b *BaseApi) ChangeFileName(c *gin.Context) {

View File

@ -0,0 +1,23 @@
package buserr
import (
"bytes"
"fmt"
"sort"
)
type MultiErr map[string]error
func (e MultiErr) Error() string {
var keys []string
for key := range e {
keys = append(keys, key)
}
sort.Strings(keys)
buffer := bytes.NewBufferString("")
for _, key := range keys {
buffer.WriteString(fmt.Sprintf("[%s] %s\n", key, e[key]))
}
return buffer.String()
}

View File

@ -206,7 +206,6 @@ func (c *AcmeClient) GetDNSResolve(domains []string) (map[string]Resolve, error)
resolves := make(map[string]Resolve)
resc, errc := make(chan acme.Authorization), make(chan domainError)
for _, authzURL := range order.Authorizations {
go func(authzURL string) {
authz, err := core.Authorizations.Get(authzURL)
if err != nil {
@ -215,7 +214,6 @@ func (c *AcmeClient) GetDNSResolve(domains []string) (map[string]Resolve, error)
}
resc <- authz
}(authzURL)
}
var responses []acme.Authorization