feat: 修改文件上传错误处理 (#370)

pull/371/head
zhengkunwang223 2023-03-22 18:34:29 +08:00 committed by GitHub
parent 0861b30a7b
commit a3cb8be08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 13 deletions

View File

@ -578,13 +578,16 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
} }
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
if err := fileOp.CreateDir("uploads", 0755); err != nil { tmpDir := path.Join(global.CONF.System.TmpDir, "upload")
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) if !fileOp.Stat(tmpDir) {
return if err := fileOp.CreateDir(tmpDir, 0755); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
} }
//fileID := uuid.New().String()
filename := c.PostForm("filename") filename := c.PostForm("filename")
fileDir := filepath.Join(global.CONF.System.DataDir, "upload", filename) fileDir := filepath.Join(tmpDir, filename)
_ = os.MkdirAll(fileDir, 0755) _ = os.MkdirAll(fileDir, 0755)
filePath := filepath.Join(fileDir, filename) filePath := filepath.Join(fileDir, filename)
@ -594,25 +597,25 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return return
} }
emptyFile.Close() defer emptyFile.Close()
chunkData, err := ioutil.ReadAll(uploadFile) chunkData, err := ioutil.ReadAll(uploadFile)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrFileUpload, err)
return return
} }
chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex)) chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex))
err = ioutil.WriteFile(chunkPath, chunkData, 0644) err = ioutil.WriteFile(chunkPath, chunkData, 0644)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
return return
} }
if chunkIndex+1 == chunkCount { if chunkIndex+1 == chunkCount {
err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount) err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrAppDelete, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
return return
} }
helper.SuccessWithData(c, true) helper.SuccessWithData(c, true)

View File

@ -84,6 +84,7 @@ var (
ErrMovePathFailed = "ErrMovePathFailed" ErrMovePathFailed = "ErrMovePathFailed"
ErrLinkPathNotFound = "ErrLinkPathNotFound" ErrLinkPathNotFound = "ErrLinkPathNotFound"
ErrFileIsExit = "ErrFileIsExit" ErrFileIsExit = "ErrFileIsExit"
ErrFileUpload = "ErrFileUpload"
) )
//mysql //mysql

View File

@ -27,14 +27,11 @@ func (ssl *ssl) Run() {
} }
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location()) expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location())
sum := expireDate.Sub(now) sum := expireDate.Sub(now)
global.LOG.Info(expireDate)
global.LOG.Info(sum.Hours())
if sum.Hours() < 720 { if sum.Hours() < 720 {
if err := sslService.Renew(s.ID); err != nil { if err := sslService.Renew(s.ID); err != nil {
global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error()) global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error())
} }
} }
} }
global.LOG.Info("ssl renew cron job end...") global.LOG.Info("ssl renew cron job end...")
} }

View File

@ -35,6 +35,7 @@ ErrPathNotFound: "Path is not found"
ErrMovePathFailed: "The target path cannot contain the original path!" ErrMovePathFailed: "The target path cannot contain the original path!"
ErrLinkPathNotFound: "Target path does not exist!" ErrLinkPathNotFound: "Target path does not exist!"
ErrFileIsExit: "File already exists!" ErrFileIsExit: "File already exists!"
ErrFileUpload: "Failed to upload file"
#website #website
ErrDomainIsExist: "Domain is already exist" ErrDomainIsExist: "Domain is already exist"

View File

@ -35,6 +35,7 @@ ErrPathNotFound: "目录不存在"
ErrMovePathFailed: "目标路径不能包含原路径!" ErrMovePathFailed: "目标路径不能包含原路径!"
ErrLinkPathNotFound: "目标路径不存在!" ErrLinkPathNotFound: "目标路径不存在!"
ErrFileIsExit: "文件已存在!" ErrFileIsExit: "文件已存在!"
ErrFileUpload: "上传文件失败"
#website #website
ErrDomainIsExist: "域名已存在" ErrDomainIsExist: "域名已存在"

View File

@ -251,6 +251,7 @@ const submitUpload = async (file: any) => {
uploadedChunkCount++; uploadedChunkCount++;
} catch (error) { } catch (error) {
isUpload.value = false; isUpload.value = false;
break;
} }
if (uploadedChunkCount == chunkCount) { if (uploadedChunkCount == chunkCount) {
isUpload.value = false; isUpload.value = false;

View File

@ -54,7 +54,7 @@
<div v-if="slots.prompt" class="prompt"> <div v-if="slots.prompt" class="prompt">
<slot name="prompt"></slot> <slot name="prompt"></slot>
</div> </div>
<div class="main"> <div class="main-content">
<slot name="main"></slot> <slot name="main"></slot>
</div> </div>
</el-card> </el-card>
@ -133,4 +133,8 @@ const showBack = computed(() => {
.main-box { .main-box {
position: relative; position: relative;
} }
.main-content {
margin-top: 20px;
}
</style> </style>

View File

@ -110,6 +110,7 @@ const submit = async () => {
uploadedChunkCount++; uploadedChunkCount++;
} catch (error) { } catch (error) {
loading.value = false; loading.value = false;
break;
} }
if (uploadedChunkCount == chunkCount) { if (uploadedChunkCount == chunkCount) {
loading.value = false; loading.value = false;