|
|
|
@@ -6,6 +6,7 @@ import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
|
|
|
|
@@ -295,13 +296,64 @@ func DownloadMultiModelFile(ctx *context.Context) { |
|
|
|
|
|
|
|
path := Model_prefix + models.AttachmentRelativePath(id) + "/" |
|
|
|
if task.Type == models.TypeCloudBrainTwo { |
|
|
|
|
|
|
|
downloadFromCloudBrainTwo(path, task, ctx, id) |
|
|
|
} else if task.Type == models.TypeCloudBrainOne { |
|
|
|
|
|
|
|
downloadFromCloudBrainOne(path, task, ctx, id) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func downloadFromCloudBrainOne(path string, task *models.AiModelManage, ctx *context.Context, id string) { |
|
|
|
allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path) |
|
|
|
if err == nil { |
|
|
|
//count++ |
|
|
|
models.ModifyModelDownloadCount(id) |
|
|
|
|
|
|
|
returnFileName := task.Name + "_" + task.Version + ".zip" |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(returnFileName)) |
|
|
|
ctx.Resp.Header().Set("Content-Type", "application/octet-stream") |
|
|
|
w := zip.NewWriter(ctx.Resp) |
|
|
|
defer w.Close() |
|
|
|
for _, oneFile := range allFile { |
|
|
|
if oneFile.IsDir { |
|
|
|
log.Info("zip dir name:" + oneFile.FileName) |
|
|
|
} else { |
|
|
|
log.Info("zip file name:" + oneFile.FileName) |
|
|
|
fDest, err := w.Create(oneFile.FileName) |
|
|
|
if err != nil { |
|
|
|
log.Info("create zip entry error, download file failed: %s\n", err.Error()) |
|
|
|
ctx.ServerError("download file failed:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
body, err := storage.ObsDownloadAFile(setting.Bucket, path+oneFile.FileName) |
|
|
|
if err != nil { |
|
|
|
log.Info("download file failed: %s\n", err.Error()) |
|
|
|
ctx.ServerError("download file failed:", err) |
|
|
|
return |
|
|
|
} else { |
|
|
|
defer body.Close() |
|
|
|
p := make([]byte, 1024) |
|
|
|
var readErr error |
|
|
|
var readCount int |
|
|
|
// 读取对象内容 |
|
|
|
for { |
|
|
|
readCount, readErr = body.Read(p) |
|
|
|
if readCount > 0 { |
|
|
|
fDest.Write(p[:readCount]) |
|
|
|
} |
|
|
|
if readErr != nil { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("error,msg=" + err.Error()) |
|
|
|
ctx.ServerError("no file to download.", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func downloadFromCloudBrainTwo(path string, task *models.AiModelManage, ctx *context.Context, id string) { |
|
|
|
allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path) |
|
|
|
if err == nil { |
|
|
|
@@ -309,7 +361,7 @@ func downloadFromCloudBrainTwo(path string, task *models.AiModelManage, ctx *con |
|
|
|
models.ModifyModelDownloadCount(id) |
|
|
|
|
|
|
|
returnFileName := task.Name + "_" + task.Version + ".zip" |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+returnFileName) |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(returnFileName)) |
|
|
|
ctx.Resp.Header().Set("Content-Type", "application/octet-stream") |
|
|
|
w := zip.NewWriter(ctx.Resp) |
|
|
|
defer w.Close() |
|
|
|
|