mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-22 22:04:08 +08:00
parent
9c357f1ea4
commit
b80b67b060
1 changed files with 17 additions and 4 deletions
|
@ -592,7 +592,7 @@ func (b *BaseApi) Size(c *gin.Context) {
|
||||||
helper.SuccessWithData(c, res)
|
helper.SuccessWithData(c, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int) error {
|
func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int, overwrite bool) error {
|
||||||
op := files.NewFileOp()
|
op := files.NewFileOp()
|
||||||
dstDir = strings.TrimSpace(dstDir)
|
dstDir = strings.TrimSpace(dstDir)
|
||||||
mode, _ := files.GetParentMode(dstDir)
|
mode, _ := files.GetParentMode(dstDir)
|
||||||
|
@ -604,8 +604,17 @@ func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dstFileName := filepath.Join(dstDir, fileName)
|
||||||
targetFile, err := os.OpenFile(filepath.Join(dstDir, fileName), os.O_RDWR|os.O_CREATE, mode)
|
dstInfo, statErr := os.Stat(dstFileName)
|
||||||
|
if statErr == nil {
|
||||||
|
mode = dstInfo.Mode()
|
||||||
|
} else {
|
||||||
|
mode = 0644
|
||||||
|
}
|
||||||
|
if overwrite {
|
||||||
|
_ = os.Remove(dstFileName)
|
||||||
|
}
|
||||||
|
targetFile, err := os.OpenFile(dstFileName, os.O_RDWR|os.O_CREATE, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -704,7 +713,11 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if chunkIndex+1 == chunkCount {
|
if chunkIndex+1 == chunkCount {
|
||||||
err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount)
|
overwrite := true
|
||||||
|
if ow := c.PostForm("overwrite"); ow != "" {
|
||||||
|
overwrite, _ = strconv.ParseBool(ow)
|
||||||
|
}
|
||||||
|
err = mergeChunks(filename, fileDir, c.PostForm("path"), chunkCount, overwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, buserr.WithMap(constant.ErrFileUpload, map[string]interface{}{"name": filename, "detail": err.Error()}, err))
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, buserr.WithMap(constant.ErrFileUpload, map[string]interface{}{"name": filename, "detail": err.Error()}, err))
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue