|
|
|
@@ -3,6 +3,7 @@ package image |
|
|
|
import ( |
|
|
|
"PCM/adaptor/PCM-CORE/model" |
|
|
|
result2 "PCM/common/result" |
|
|
|
"PCM/common/tool" |
|
|
|
"bufio" |
|
|
|
"context" |
|
|
|
"encoding/base64" |
|
|
|
@@ -32,7 +33,7 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
name := r.PostFormValue("name") |
|
|
|
dataType := r.PostFormValue("dataType") |
|
|
|
// 对比合并请求的文件大小和已上传文件夹大小 |
|
|
|
toSize, _ := getDirSize(filepath.Join(uploadTempPath, hash)) |
|
|
|
toSize, _ := tool.GetDirSize(filepath.Join(uploadTempPath, hash)) |
|
|
|
if size != toSize { |
|
|
|
fmt.Fprintf(w, "文件上传错误") |
|
|
|
} |
|
|
|
@@ -45,7 +46,7 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
filesSort[nameArr[1]] = f.Name() |
|
|
|
} |
|
|
|
saveFile := filepath.Join(uploadPath, name) |
|
|
|
if exists, _ := PathExists(saveFile); exists { |
|
|
|
if exists, _ := tool.PathExists(saveFile); exists { |
|
|
|
os.Remove(saveFile) |
|
|
|
} |
|
|
|
fs, _ := os.OpenFile(saveFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, os.ModeAppend|os.ModePerm) |
|
|
|
@@ -62,7 +63,6 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
data, err := ioutil.ReadFile(fileName) |
|
|
|
fmt.Println(err) |
|
|
|
fs.Write(data) |
|
|
|
|
|
|
|
wg.Done() |
|
|
|
} |
|
|
|
wg.Wait() |
|
|
|
@@ -90,7 +90,7 @@ func ChunkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
|
return |
|
|
|
} |
|
|
|
// 删除本地文件 避免占用本地存储资源 |
|
|
|
err = os.Remove(filepath.Join(uploadPath, name)) |
|
|
|
go os.Remove(filepath.Join(uploadPath, name)) |
|
|
|
result2.HttpResult(r, w, nil, err) |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -108,14 +108,15 @@ func pushImage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
fileInfo, err := os.Open(filepath.Join(uploadPath, name)) |
|
|
|
defer fileInfo.Close() |
|
|
|
reader := bufio.NewReader(fileInfo) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
body, err := svcCtx.DockerClient.ImageLoad(context.Background(), reader, false) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
bytes, err := ioutil.ReadAll(body.Body) |
|
|
|
|
|
|
|
loadBody := LoadBody{} |
|
|
|
@@ -150,15 +151,3 @@ func pushImage(svcCtx *svc.ServiceContext, name string) error { |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// DirSize 获取整体文件夹大小 |
|
|
|
func getDirSize(path string) (int64, error) { |
|
|
|
var size int64 |
|
|
|
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { |
|
|
|
if !info.IsDir() { |
|
|
|
size += info.Size() |
|
|
|
} |
|
|
|
return err |
|
|
|
}) |
|
|
|
return size, err |
|
|
|
} |