diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index c3fe34043..9a12df6d4 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -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) { diff --git a/backend/buserr/multi_err.go b/backend/buserr/multi_err.go new file mode 100644 index 000000000..bf0c875ce --- /dev/null +++ b/backend/buserr/multi_err.go @@ -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() +} diff --git a/backend/utils/ssl/client.go b/backend/utils/ssl/client.go index ccefdc807..3e1237629 100644 --- a/backend/utils/ssl/client.go +++ b/backend/utils/ssl/client.go @@ -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