mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 解决上传文件根目录报错的BUG
This commit is contained in:
parent
7e9231a527
commit
587c3df06a
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
|
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"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"))
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error paths in request"))
|
||||||
return
|
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.Stat(dir); err != nil && os.IsNotExist(err) {
|
||||||
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,15 +182,21 @@ func (b *BaseApi) UploadFiles(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
success := 0
|
success := 0
|
||||||
|
failures := make(buserr.MultiErr)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
err := c.SaveUploadedFile(file, path.Join(paths[0], file.Filename))
|
if err := c.SaveUploadedFile(file, path.Join(paths[0], file.Filename)); err != nil {
|
||||||
if err != nil {
|
e := fmt.Errorf("upload [%s] file failed, err: %v", file.Filename, err)
|
||||||
global.LOG.Errorf("upload [%s] file failed, err: %v", file.Filename, err)
|
failures[file.Filename] = e
|
||||||
|
global.LOG.Error(e)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
success++
|
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) {
|
func (b *BaseApi) ChangeFileName(c *gin.Context) {
|
||||||
|
23
backend/buserr/multi_err.go
Normal file
23
backend/buserr/multi_err.go
Normal 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()
|
||||||
|
}
|
@ -206,7 +206,6 @@ func (c *AcmeClient) GetDNSResolve(domains []string) (map[string]Resolve, error)
|
|||||||
resolves := make(map[string]Resolve)
|
resolves := make(map[string]Resolve)
|
||||||
resc, errc := make(chan acme.Authorization), make(chan domainError)
|
resc, errc := make(chan acme.Authorization), make(chan domainError)
|
||||||
for _, authzURL := range order.Authorizations {
|
for _, authzURL := range order.Authorizations {
|
||||||
|
|
||||||
go func(authzURL string) {
|
go func(authzURL string) {
|
||||||
authz, err := core.Authorizations.Get(authzURL)
|
authz, err := core.Authorizations.Get(authzURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,7 +214,6 @@ func (c *AcmeClient) GetDNSResolve(domains []string) (map[string]Resolve, error)
|
|||||||
}
|
}
|
||||||
resc <- authz
|
resc <- authz
|
||||||
}(authzURL)
|
}(authzURL)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var responses []acme.Authorization
|
var responses []acme.Authorization
|
||||||
|
Loading…
x
Reference in New Issue
Block a user