From 47dcd507bf2b2626ccd01fa79399b98c4fb99634 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 15 Jun 2021 17:48:08 +0800 Subject: [PATCH] download-model --- modules/storage/minio.go | 2 +- routers/repo/attachment.go | 2 +- routers/repo/cloudbrain.go | 34 ++++++++++++++++------ routers/repo/dir.go | 15 ++++++---- templates/repo/datasets/dirs/dir_list.tmpl | 2 +- 5 files changed, 38 insertions(+), 17 deletions(-) mode change 100644 => 100755 modules/storage/minio.go diff --git a/modules/storage/minio.go b/modules/storage/minio.go old mode 100644 new mode 100755 index 83a60f376..b14442d56 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -83,7 +83,7 @@ func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string, er reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"") 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 { return "", err } diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 086965bdf..b59f4ffc7 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -205,7 +205,7 @@ func GetAttachment(ctx *context.Context) { if setting.Attachment.StoreType == storage.MinioStorageType { url := "" 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 { ctx.ServerError("PresignedGetURL", err) return diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 7cac900c6..e70944150 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -338,37 +338,53 @@ func CloudBrainDel(ctx *context.Context) { func CloudBrainShowModels(ctx *context.Context) { ctx.Data["PageIsCloudBrain"] = true - var jobID = ctx.Params(":jobid") + jobID := ctx.Params(":jobid") + parentDir := ctx.Query("parentDir") task, err := models.GetCloudbrainByJobID(jobID) if err != nil { log.Error("no such job!") - ctx.RenderWithErr("no such job!", tplCloudBrainIndex, nil) + ctx.ServerError("no such job:", err) return } //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["jobID"] = jobID ctx.HTML(200, tplCloudBrainShowModels) } -func getModelDirs(uuid string, parentDir string) (string, error) { +func getModelDirs(jobName string, parentDir string) (string, error) { var req string + modelActualPath := setting.JobPath + jobName + "/model/" if parentDir == "" { - req = "uuid=" + uuid + req = "baseDir=" + modelActualPath } else { - req = "uuid=" + uuid + "&parentDir=" + parentDir + req = "baseDir=" + modelActualPath + "&parentDir=" + parentDir } return getDirs(req) } 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) if err != nil { log.Error("PresignedGetURL failed: %v", err.Error()) diff --git a/routers/repo/dir.go b/routers/repo/dir.go index ea1f80498..d1dfbcd11 100755 --- a/routers/repo/dir.go +++ b/routers/repo/dir.go @@ -60,8 +60,8 @@ func DirIndex(ctx *context.Context) { dirs, err := getDatasetDirs(uuid, parentDir) 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 } @@ -83,10 +83,15 @@ func DirIndex(ctx *context.Context) { func getDatasetDirs(uuid string, parentDir string) (string, error) { var req string + dataActualPath := setting.Attachment.Minio.RealPath + + setting.Attachment.Minio.Bucket + "/" + + setting.Attachment.Minio.BasePath + + models.AttachmentRelativePath(uuid) + + uuid + "/" if parentDir == "" { - req = "uuid=" + uuid + req = "baseDir=" + dataActualPath } else { - req = "uuid=" + uuid + "&parentDir=" + parentDir + req = "baseDir=" + dataActualPath + "&parentDir=" + parentDir } return getDirs(req) @@ -95,7 +100,7 @@ func getDatasetDirs(uuid string, parentDir string) (string, error) { func getDirs(req string) (string, error) { var dirs string - url := setting.DecompressAddress + "/dirs/dataset?" + req + url := setting.DecompressAddress + "/dirs?" + req reqHttp, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { log.Error("http.NewRequest failed:", err.Error()) diff --git a/templates/repo/datasets/dirs/dir_list.tmpl b/templates/repo/datasets/dirs/dir_list.tmpl index 9d10f509c..975dccef0 100755 --- a/templates/repo/datasets/dirs/dir_list.tmpl +++ b/templates/repo/datasets/dirs/dir_list.tmpl @@ -6,7 +6,7 @@