@@ -337,20 +337,3 @@ func ObsCreateObject(path string) error { | |||
return nil | |||
} | |||
func ObsDownloadAFile(bucket string, key string) (io.ReadCloser, error) { | |||
input := &obs.GetObjectInput{} | |||
input.Bucket = bucket | |||
input.Key = key | |||
output, err := ObsCli.GetObject(input) | |||
if err == nil { | |||
log.Info("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s\n", | |||
output.StorageClass, output.ETag, output.ContentType, output.ContentLength, output.LastModified) | |||
return output.Body, nil | |||
} else if obsError, ok := err.(obs.ObsError); ok { | |||
log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message) | |||
return nil, obsError | |||
} else { | |||
return nil, err | |||
} | |||
} |
@@ -880,7 +880,6 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Post("/del_version", repo.DelTrainJobVersion) | |||
m.Post("/stop_version", repo.StopTrainJobVersion) | |||
m.Get("/model_list", repo.ModelList) | |||
m.Get("/model_download", repo.ModelDownload) | |||
}) | |||
}) | |||
}, reqRepoReader(models.UnitTypeCloudBrain)) | |||
@@ -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) | |||
} | |||
} |
@@ -478,7 +478,6 @@ func TrainJobNewVersion(ctx *context.Context) { | |||
func trainJobNewVersionDataPrepare(ctx *context.Context) error { | |||
ctx.Data["PageIsCloudBrain"] = true | |||
var jobID = ctx.Params(":jobid") | |||
// var versionName = ctx.Params(":version-name") | |||
var versionName = ctx.Query("version_name") | |||
// canNewJob, err := canUserCreateTrainJobVersion(ctx, jobID, versionName) | |||
// if err != nil { | |||
@@ -548,7 +547,7 @@ func trainJobNewVersionDataPrepare(ctx *context.Context) error { | |||
return err | |||
} | |||
ctx.Data["branch"] = Branches | |||
ctx.Data["branches"] = Branches | |||
ctx.Data["branch_name"] = task.BranchName | |||
ctx.Data["description"] = task.Description | |||
ctx.Data["boot_file"] = task.BootFile | |||
@@ -1388,12 +1387,9 @@ func ModelDownload(ctx *context.Context) { | |||
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()) | |||
@@ -1402,40 +1398,12 @@ func ModelDownload(ctx *context.Context) { | |||
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) | |||
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 | |||
} | |||
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) | |||
} |