|
|
|
@@ -7,7 +7,6 @@ package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"path" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
|
|
|
|
@@ -15,7 +14,6 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/modelarts" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/storage" |
|
|
|
) |
|
|
|
|
|
|
|
@@ -321,62 +319,3 @@ func ModelList(ctx *context.APIContext) { |
|
|
|
"PageIsCloudBrain": true, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func ModelDownload(ctx *context.Context) { |
|
|
|
var ( |
|
|
|
err error |
|
|
|
) |
|
|
|
|
|
|
|
var jobID = ctx.Params(":jobid") |
|
|
|
versionName := ctx.Query("version_name") |
|
|
|
// versionName := "V0001" |
|
|
|
parentDir := ctx.Query("parent_dir") |
|
|
|
fileName := ctx.Query("file_name") |
|
|
|
log.Info("DownloadSingleModelFile start.") |
|
|
|
// id := ctx.Params(":ID") |
|
|
|
// path := Model_prefix + models.AttachmentRelativePath(id) + "/" + parentDir + fileName |
|
|
|
task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
path := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, setting.OutPutPath, versionName, parentDir, fileName), "/") |
|
|
|
log.Info("Download path is:%s", path) |
|
|
|
if setting.PROXYURL == "" { |
|
|
|
body, err := storage.ObsDownloadAFile(setting.Bucket, path) |
|
|
|
if err != nil { |
|
|
|
log.Info("download error.") |
|
|
|
} else { |
|
|
|
//count++ |
|
|
|
// models.ModifyModelDownloadCount(id) |
|
|
|
defer body.Close() |
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName) |
|
|
|
ctx.Resp.Header().Set("Content-Type", "application/octet-stream") |
|
|
|
p := make([]byte, 1024) |
|
|
|
var readErr error |
|
|
|
var readCount int |
|
|
|
// 读取对象内容 |
|
|
|
for { |
|
|
|
readCount, readErr = body.Read(p) |
|
|
|
if readCount > 0 { |
|
|
|
ctx.Resp.Write(p[:readCount]) |
|
|
|
//fmt.Printf("%s", p[:readCount]) |
|
|
|
} |
|
|
|
if readErr != nil { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, path) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetObsCreateSignedUrl failed: %v", err.Error(), ctx.Data["msgID"]) |
|
|
|
ctx.ServerError("GetObsCreateSignedUrl", err) |
|
|
|
return |
|
|
|
} |
|
|
|
//count++ |
|
|
|
// models.ModifyModelDownloadCount(id) |
|
|
|
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) |
|
|
|
} |
|
|
|
} |