Browse Source

download-model

tags/v1.21.12.1
lewis 4 years ago
parent
commit
ffb7b87097
5 changed files with 38 additions and 17 deletions
  1. +1
    -1
      modules/storage/minio.go
  2. +1
    -1
      routers/repo/attachment.go
  3. +25
    -9
      routers/repo/cloudbrain.go
  4. +10
    -5
      routers/repo/dir.go
  5. +1
    -1
      templates/repo/datasets/dirs/dir_list.tmpl

+ 1
- 1
modules/storage/minio.go View File

@@ -83,7 +83,7 @@ func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string, er
reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"") reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"")


var preURL *url.URL var preURL *url.URL
preURL, err := m.client.PresignedGetObject(m.bucket, m.buildMinioPath(path), PresignedGetUrlExpireTime, reqParams)
preURL, err := m.client.PresignedGetObject(m.bucket, path, PresignedGetUrlExpireTime, reqParams)
if err != nil { if err != nil {
return "", err return "", err
} }


+ 1
- 1
routers/repo/attachment.go View File

@@ -205,7 +205,7 @@ func GetAttachment(ctx *context.Context) {
if setting.Attachment.StoreType == storage.MinioStorageType { if setting.Attachment.StoreType == storage.MinioStorageType {
url := "" url := ""
if typeCloudBrain == models.TypeCloudBrainOne { if typeCloudBrain == models.TypeCloudBrainOne {
url, err = storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name)
url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath + attach.RelativePath(), attach.Name)
if err != nil { if err != nil {
ctx.ServerError("PresignedGetURL", err) ctx.ServerError("PresignedGetURL", err)
return return


+ 25
- 9
routers/repo/cloudbrain.go View File

@@ -338,37 +338,53 @@ func CloudBrainDel(ctx *context.Context) {
func CloudBrainShowModels(ctx *context.Context) { func CloudBrainShowModels(ctx *context.Context) {
ctx.Data["PageIsCloudBrain"] = true ctx.Data["PageIsCloudBrain"] = true


var jobID = ctx.Params(":jobid")
jobID := ctx.Params(":jobid")
parentDir := ctx.Query("parentDir")
task, err := models.GetCloudbrainByJobID(jobID) task, err := models.GetCloudbrainByJobID(jobID)
if err != nil { if err != nil {
log.Error("no such job!") log.Error("no such job!")
ctx.RenderWithErr("no such job!", tplCloudBrainIndex, nil)
ctx.ServerError("no such job:", err)
return return
} }


//get dirs //get dirs
dirs, err := getModelDirs(task.JobName, parentDir)
if err != nil {
log.Error("getModelDirs failed:", err.Error())
ctx.ServerError("getModelDirs failed:", err)
return
}


var fileInfos []FileInfo
err = json.Unmarshal([]byte(dirs), &fileInfos)
if err != nil {
log.Error("json.Unmarshal failed:", err.Error())
ctx.ServerError("json.Unmarshal failed:", err)
return
}



ctx.Data["Dirs"] = fileInfos
ctx.Data["task"] = task ctx.Data["task"] = task
ctx.Data["jobID"] = jobID
ctx.HTML(200, tplCloudBrainShowModels) ctx.HTML(200, tplCloudBrainShowModels)
} }


func getModelDirs(uuid string, parentDir string) (string, error) {
func getModelDirs(jobName string, parentDir string) (string, error) {
var req string var req string
modelActualPath := setting.JobPath + jobName + "/model/"
if parentDir == "" { if parentDir == "" {
req = "uuid=" + uuid
req = "baseDir=" + modelActualPath
} else { } else {
req = "uuid=" + uuid + "&parentDir=" + parentDir
req = "baseDir=" + modelActualPath + "&parentDir=" + parentDir
} }


return getDirs(req) return getDirs(req)
} }


func CloudBrainDownloadModel(ctx *context.Context) { func CloudBrainDownloadModel(ctx *context.Context) {
filePath := ctx.Query("file_path")
fileName := ctx.Query("file_name")
parentDir := ctx.Query("parentDir")
fileName := ctx.Query("fileName")
jobName := ctx.Query("jobName")
filePath := "jobs/" +jobName + "/model/" + parentDir
url, err := storage.Attachments.PresignedGetURL(filePath, fileName) url, err := storage.Attachments.PresignedGetURL(filePath, fileName)
if err != nil { if err != nil {
log.Error("PresignedGetURL failed: %v", err.Error()) log.Error("PresignedGetURL failed: %v", err.Error())


+ 10
- 5
routers/repo/dir.go View File

@@ -60,8 +60,8 @@ func DirIndex(ctx *context.Context) {


dirs, err := getDatasetDirs(uuid, parentDir) dirs, err := getDatasetDirs(uuid, parentDir)
if err != nil { if err != nil {
log.Error("getDirs failed:", err.Error())
ctx.ServerError("getDirs failed:", err)
log.Error("getDatasetDirs failed:", err.Error())
ctx.ServerError("getDatasetDirs failed:", err)
return return
} }


@@ -83,10 +83,15 @@ func DirIndex(ctx *context.Context) {


func getDatasetDirs(uuid string, parentDir string) (string, error) { func getDatasetDirs(uuid string, parentDir string) (string, error) {
var req string var req string
dataActualPath := setting.Attachment.Minio.RealPath +
setting.Attachment.Minio.Bucket + "/" +
setting.Attachment.Minio.BasePath +
models.AttachmentRelativePath(uuid) +
uuid + "/"
if parentDir == "" { if parentDir == "" {
req = "uuid=" + uuid
req = "baseDir=" + dataActualPath
} else { } else {
req = "uuid=" + uuid + "&parentDir=" + parentDir
req = "baseDir=" + dataActualPath + "&parentDir=" + parentDir
} }


return getDirs(req) return getDirs(req)
@@ -95,7 +100,7 @@ func getDatasetDirs(uuid string, parentDir string) (string, error) {
func getDirs(req string) (string, error) { func getDirs(req string) (string, error) {
var dirs string var dirs string


url := setting.DecompressAddress + "/dirs/dataset?" + req
url := setting.DecompressAddress + "/dirs?" + req
reqHttp, err := http.NewRequest(http.MethodGet, url, nil) reqHttp, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil { if err != nil {
log.Error("http.NewRequest failed:", err.Error()) log.Error("http.NewRequest failed:", err.Error())


+ 1
- 1
templates/repo/datasets/dirs/dir_list.tmpl View File

@@ -6,7 +6,7 @@
<td class="name four wide"> <td class="name four wide">
<span class="truncate"> <span class="truncate">
<span class="octicon octicon-file-directory"></span> <span class="octicon octicon-file-directory"></span>
<a class="title" href="{{if .IsDir}}{{$.RepoLink}}/datasets/dirs/.Uuid?parentDir={{.ParenDir}}{{end}}">
<a class="title" href="{{if .IsDir}}{{$.RepoLink}}/datasets/dirs/{{$.Uuid}}?parentDir={{.ParenDir}}{{end}}">
<span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}} <span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}}
</a> </a>
</span> </span>


Loading…
Cancel
Save