mirror of https://github.com/1Panel-dev/1Panel
feat: 修改文件上传错误处理 (#370)
parent
0861b30a7b
commit
a3cb8be08f
|
@ -578,13 +578,16 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
|
|||
}
|
||||
|
||||
fileOp := files.NewFileOp()
|
||||
if err := fileOp.CreateDir("uploads", 0755); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
tmpDir := path.Join(global.CONF.System.TmpDir, "upload")
|
||||
if !fileOp.Stat(tmpDir) {
|
||||
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")
|
||||
fileDir := filepath.Join(global.CONF.System.DataDir, "upload", filename)
|
||||
fileDir := filepath.Join(tmpDir, filename)
|
||||
|
||||
_ = os.MkdirAll(fileDir, 0755)
|
||||
filePath := filepath.Join(fileDir, filename)
|
||||
|
@ -594,25 +597,25 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
|
|||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
emptyFile.Close()
|
||||
defer emptyFile.Close()
|
||||
|
||||
chunkData, err := ioutil.ReadAll(uploadFile)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrFileUpload, err)
|
||||
return
|
||||
}
|
||||
|
||||
chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex))
|
||||
err = ioutil.WriteFile(chunkPath, chunkData, 0644)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
|
||||
return
|
||||
}
|
||||
|
||||
if chunkIndex+1 == chunkCount {
|
||||
err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount)
|
||||
if err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrAppDelete, err)
|
||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, true)
|
||||
|
|
|
@ -84,6 +84,7 @@ var (
|
|||
ErrMovePathFailed = "ErrMovePathFailed"
|
||||
ErrLinkPathNotFound = "ErrLinkPathNotFound"
|
||||
ErrFileIsExit = "ErrFileIsExit"
|
||||
ErrFileUpload = "ErrFileUpload"
|
||||
)
|
||||
|
||||
//mysql
|
||||
|
|
|
@ -27,14 +27,11 @@ func (ssl *ssl) Run() {
|
|||
}
|
||||
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location())
|
||||
sum := expireDate.Sub(now)
|
||||
global.LOG.Info(expireDate)
|
||||
global.LOG.Info(sum.Hours())
|
||||
if sum.Hours() < 720 {
|
||||
if err := sslService.Renew(s.ID); err != nil {
|
||||
global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.LOG.Info("ssl renew cron job end...")
|
||||
}
|
||||
|
|
|
@ -35,6 +35,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"
|
||||
|
||||
#website
|
||||
ErrDomainIsExist: "Domain is already exist"
|
||||
|
|
|
@ -35,6 +35,7 @@ ErrPathNotFound: "目录不存在"
|
|||
ErrMovePathFailed: "目标路径不能包含原路径!"
|
||||
ErrLinkPathNotFound: "目标路径不存在!"
|
||||
ErrFileIsExit: "文件已存在!"
|
||||
ErrFileUpload: "上传文件失败"
|
||||
|
||||
#website
|
||||
ErrDomainIsExist: "域名已存在"
|
||||
|
|
|
@ -251,6 +251,7 @@ const submitUpload = async (file: any) => {
|
|||
uploadedChunkCount++;
|
||||
} catch (error) {
|
||||
isUpload.value = false;
|
||||
break;
|
||||
}
|
||||
if (uploadedChunkCount == chunkCount) {
|
||||
isUpload.value = false;
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
<div v-if="slots.prompt" class="prompt">
|
||||
<slot name="prompt"></slot>
|
||||
</div>
|
||||
<div class="main">
|
||||
<div class="main-content">
|
||||
<slot name="main"></slot>
|
||||
</div>
|
||||
</el-card>
|
||||
|
@ -133,4 +133,8 @@ const showBack = computed(() => {
|
|||
.main-box {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -110,6 +110,7 @@ const submit = async () => {
|
|||
uploadedChunkCount++;
|
||||
} catch (error) {
|
||||
loading.value = false;
|
||||
break;
|
||||
}
|
||||
if (uploadedChunkCount == chunkCount) {
|
||||
loading.value = false;
|
||||
|
|
Loading…
Reference in New Issue