feat: 优化文件上传逻辑,减少临时空间占用 (#5508)

Refs https://github.com/1Panel-dev/1Panel/issues/5184
This commit is contained in:
zhengkunwang 2024-06-19 17:54:58 +08:00 committed by GitHub
parent 1577581257
commit 003c87bf00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -593,6 +593,10 @@ func (b *BaseApi) Size(c *gin.Context) {
} }
func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int, overwrite bool) error { func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int, overwrite bool) error {
defer func() {
_ = os.RemoveAll(fileDir)
}()
op := files.NewFileOp() op := files.NewFileOp()
dstDir = strings.TrimSpace(dstDir) dstDir = strings.TrimSpace(dstDir)
mode, _ := files.GetParentMode(dstDir) mode, _ := files.GetParentMode(dstDir)
@ -629,9 +633,10 @@ func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int,
if err != nil { if err != nil {
return err return err
} }
_ = os.Remove(chunkPath)
} }
return files.NewFileOp().DeleteDir(fileDir) return nil
} }
// @Tags File // @Tags File