From 2d6925ac4f0f67058df772ae753525a2b65e74b8 Mon Sep 17 00:00:00 2001
From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com>
Date: Sat, 27 May 2023 23:15:30 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E4=B8=8A=E4=BC=A0=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=20(#1168)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/api/v1/file.go | 26 ++--
backend/i18n/lang/en.yaml | 2 +-
backend/i18n/lang/zh.yaml | 2 +-
frontend/src/lang/modules/en.ts | 2 +
frontend/src/lang/modules/zh.ts | 2 +
.../host/file-management/upload/index.vue | 113 +++++++++++-------
6 files changed, 93 insertions(+), 54 deletions(-)
diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go
index 87b293113..160213f97 100644
--- a/backend/app/api/v1/file.go
+++ b/backend/app/api/v1/file.go
@@ -575,6 +575,7 @@ func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int)
// @Security ApiKeyAuth
// @Router /files/chunkupload [post]
func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
+ var err error
fileForm, err := c.FormFile("chunk")
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
@@ -585,19 +586,16 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
-
chunkIndex, err := strconv.Atoi(c.PostForm("chunkIndex"))
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
-
chunkCount, err := strconv.Atoi(c.PostForm("chunkCount"))
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
-
fileOp := files.NewFileOp()
tmpDir := path.Join(global.CONF.System.TmpDir, "upload")
if !fileOp.Stat(tmpDir) {
@@ -606,37 +604,45 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
return
}
}
-
filename := c.PostForm("filename")
fileDir := filepath.Join(tmpDir, filename)
-
_ = os.MkdirAll(fileDir, 0755)
filePath := filepath.Join(fileDir, filename)
- emptyFile, err := os.Create(filePath)
+ defer func() {
+ if err != nil {
+ _ = os.Remove(fileDir)
+ }
+ }()
+ var (
+ emptyFile *os.File
+ chunkData []byte
+ )
+
+ emptyFile, err = os.Create(filePath)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
defer emptyFile.Close()
- chunkData, err := io.ReadAll(uploadFile)
+ chunkData, err = io.ReadAll(uploadFile)
if err != nil {
- helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrFileUpload, err)
+ helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, buserr.WithMap(constant.ErrFileUpload, map[string]interface{}{"name": filename, "detail": err.Error()}, err))
return
}
chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex))
err = os.WriteFile(chunkPath, chunkData, 0644)
if err != nil {
- helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
+ helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, buserr.WithMap(constant.ErrFileUpload, map[string]interface{}{"name": filename, "detail": err.Error()}, err))
return
}
if chunkIndex+1 == chunkCount {
err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount)
if err != nil {
- helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
+ helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, buserr.WithMap(constant.ErrFileUpload, map[string]interface{}{"name": filename, "detail": err.Error()}, err))
return
}
helper.SuccessWithData(c, true)
diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml
index b01ee7833..64db71e2c 100644
--- a/backend/i18n/lang/en.yaml
+++ b/backend/i18n/lang/en.yaml
@@ -39,7 +39,7 @@ ErrPathNotFound: "Path is not found"
ErrMovePathFailed: "The target path cannot contain the original path!"
ErrLinkPathNotFound: "Target path does not exist!"
ErrFileIsExit: "File already exists!"
-ErrFileUpload: "Failed to upload file"
+ErrFileUpload: "Failed to upload file {{.name}} {{.detail}}"
#website
ErrDomainIsExist: "Domain is already exist"
diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml
index 86dc3814c..233eb103b 100644
--- a/backend/i18n/lang/zh.yaml
+++ b/backend/i18n/lang/zh.yaml
@@ -39,7 +39,7 @@ ErrPathNotFound: "目录不存在"
ErrMovePathFailed: "目标路径不能包含原路径!"
ErrLinkPathNotFound: "目标路径不存在!"
ErrFileIsExit: "文件已存在!"
-ErrFileUpload: "上传文件失败"
+ErrFileUpload: "{{ .name }} 上传文件失败 {{ .detail}}"
#website
ErrDomainIsExist: "域名已存在"
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index dd998c244..0cb32393f 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -849,6 +849,8 @@ const message = {
ownerHelper:
'The default user of the PHP operating environment: the user group is 1000:1000, it is normal that the users inside and outside the container show inconsistencies',
searchHelper: 'Support wildcards such as *',
+ uploadFailed: '[{0}] File Upload file',
+ fileUploadStart: 'Uploading [{0}]....',
},
ssh: {
sshOperate: 'Operation [{0}] on the SSH service is performed. Do you want to continue?',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index be5ea796d..4e31ff930 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -852,6 +852,8 @@ const message = {
containSub: '同时修改子文件属性',
ownerHelper: 'PHP 运行环境默认用户:用户组为 1000:1000, 容器内外用户显示不一致为正常现象',
searchHelper: '支持 * 等通配符',
+ uploadFailed: '[{0}] 文件上传失败',
+ fileUploadStart: '正在上传[{0}]....',
},
ssh: {
sshOperate: '对 SSH 服务进行 [{0}] 操作,是否继续?',
diff --git a/frontend/src/views/host/file-management/upload/index.vue b/frontend/src/views/host/file-management/upload/index.vue
index d1655e416..77db2460f 100644
--- a/frontend/src/views/host/file-management/upload/index.vue
+++ b/frontend/src/views/host/file-management/upload/index.vue
@@ -15,8 +15,10 @@
:auto-upload="false"
ref="uploadRef"
:on-change="fileOnChange"
- :limit="1"
:on-exceed="handleExceed"
+ :on-success="hadleSuccess"
+ show-file-list
+ multiple
>