From 1ace40758fe7b5d6965bb34313d83b516b1f6604 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Wed, 2 Jun 2021 18:00:59 +0800 Subject: [PATCH 1/7] add interface --- routers/repo/cloudbrain.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 8d8e97377..55d809ec9 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -23,6 +23,7 @@ const ( tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" tplCloudBrainNew base.TplName = "repo/cloudbrain/new" tplCloudBrainShow base.TplName = "repo/cloudbrain/show" + tplCloudBrainShowModels base.TplName = "repo/cloudbrain/show_models" ) var ( @@ -332,6 +333,24 @@ func CloudBrainDel(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } +func CloudBrainGetModels(ctx *context.Context) { + ctx.Data["PageIsCloudBrain"] = true + + var jobID = ctx.Params(":jobid") + task, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + log.Error("no such job!") + ctx.RenderWithErr("no such job!", tplCloudBrainIndex, nil) + return + } + + + + ctx.Data["task"] = task + ctx.Data["jobID"] = jobID + ctx.HTML(200, tplCloudBrainShowModels) +} + func GetRate(ctx *context.Context) { var jobID = ctx.Params(":jobid") job, err := models.GetCloudbrainByJobID(jobID) From 21459fcb776794d1b4e9747728648b07822d2ff8 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 8 Jun 2021 16:33:43 +0800 Subject: [PATCH 2/7] 2 --- routers/repo/cloudbrain.go | 18 +++++++++++++++++- routers/routes/routes.go | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 55d809ec9..154dbb402 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -2,8 +2,10 @@ package repo import ( "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/storage" "encoding/json" "errors" + "net/http" "os" "os/exec" "strconv" @@ -333,7 +335,7 @@ func CloudBrainDel(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } -func CloudBrainGetModels(ctx *context.Context) { +func CloudBrainShowModels(ctx *context.Context) { ctx.Data["PageIsCloudBrain"] = true var jobID = ctx.Params(":jobid") @@ -344,6 +346,7 @@ func CloudBrainGetModels(ctx *context.Context) { return } + //get dirs ctx.Data["task"] = task @@ -351,6 +354,19 @@ func CloudBrainGetModels(ctx *context.Context) { ctx.HTML(200, tplCloudBrainShowModels) } +func CloudBrainDownloadModel(ctx *context.Context) { + filePath := ctx.Query("file_path") + fileName := ctx.Query("file_name") + url, err := storage.Attachments.PresignedGetURL(filePath, fileName) + if err != nil { + log.Error("PresignedGetURL failed: %v", err.Error()) + ctx.ServerError("PresignedGetURL", err) + return + } + + http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) +} + func GetRate(ctx *context.Context) { var jobID = ctx.Params(":jobid") job, err := models.GetCloudbrainByJobID(jobID) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index e8e33104d..81f15f27d 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -910,9 +910,11 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/commit_image", reqRepoCloudBrainWriter, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", reqRepoCloudBrainWriter, repo.CloudBrainStop) m.Post("/del", reqRepoCloudBrainWriter, repo.CloudBrainDel) - m.Get("/rate", reqRepoCloudBrainWriter, repo.GetRate) + m.Get("/rate", reqRepoCloudBrainReader, repo.GetRate) + m.Get("/models", reqRepoCloudBrainReader, repo.CloudBrainShowModels) + m.Get("/download_model", reqRepoCloudBrainReader, repo.CloudBrainDownloadModel) }) - m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) + m.Get("/create", reqRepoCloudBrainReader, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) }, context.RepoRef()) From 8df143d8edb61939580d0ed9c6e26e3ebc2f4143 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 15 Jun 2021 15:49:07 +0800 Subject: [PATCH 3/7] mod req --- routers/repo/cloudbrain.go | 12 ++++++++++++ routers/repo/dir.go | 15 ++++++++++----- templates/repo/datasets/dirs/dir_list.tmpl | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 154dbb402..7cac900c6 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -349,11 +349,23 @@ func CloudBrainShowModels(ctx *context.Context) { //get dirs + ctx.Data["task"] = task ctx.Data["jobID"] = jobID ctx.HTML(200, tplCloudBrainShowModels) } +func getModelDirs(uuid string, parentDir string) (string, error) { + var req string + if parentDir == "" { + req = "uuid=" + uuid + } else { + req = "uuid=" + uuid + "&parentDir=" + parentDir + } + + return getDirs(req) +} + func CloudBrainDownloadModel(ctx *context.Context) { filePath := ctx.Query("file_path") fileName := ctx.Query("file_name") diff --git a/routers/repo/dir.go b/routers/repo/dir.go index 388af34ec..ea1f80498 100755 --- a/routers/repo/dir.go +++ b/routers/repo/dir.go @@ -58,7 +58,7 @@ func DirIndex(ctx *context.Context) { dirArray = []string{attachment.Name} } - dirs, err := getDirs(uuid, parentDir) + dirs, err := getDatasetDirs(uuid, parentDir) if err != nil { log.Error("getDirs failed:", err.Error()) ctx.ServerError("getDirs failed:", err) @@ -75,13 +75,13 @@ func DirIndex(ctx *context.Context) { ctx.Data["Path"] = dirArray ctx.Data["Dirs"] = fileInfos + ctx.Data["Uuid"] = uuid ctx.Data["PageIsDataset"] = true ctx.HTML(200, tplDirIndex) } -func getDirs(uuid string, parentDir string) (string, error) { - var dirs string +func getDatasetDirs(uuid string, parentDir string) (string, error) { var req string if parentDir == "" { req = "uuid=" + uuid @@ -89,7 +89,13 @@ func getDirs(uuid string, parentDir string) (string, error) { req = "uuid=" + uuid + "&parentDir=" + parentDir } - url := setting.DecompressAddress + "/dirs?" + req + return getDirs(req) +} + +func getDirs(req string) (string, error) { + var dirs string + + url := setting.DecompressAddress + "/dirs/dataset?" + req reqHttp, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { log.Error("http.NewRequest failed:", err.Error()) @@ -127,6 +133,5 @@ func getDirs(uuid string, parentDir string) (string, error) { } dirs = resp.FileInfos - return dirs, nil } diff --git a/templates/repo/datasets/dirs/dir_list.tmpl b/templates/repo/datasets/dirs/dir_list.tmpl index 98232e17e..9d10f509c 100755 --- a/templates/repo/datasets/dirs/dir_list.tmpl +++ b/templates/repo/datasets/dirs/dir_list.tmpl @@ -6,7 +6,7 @@ - + {{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}} {{.FileName}} 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 4/7] 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 @@ - + {{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}} {{.FileName}} From 45edf55bede5d4b8dcfa9d1c3ae6d6458e15a2a6 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 17 Jun 2021 09:43:42 +0800 Subject: [PATCH 5/7] html --- routers/repo/cloudbrain.go | 3 +- templates/repo/cloudbrain/index.tmpl | 10 +++---- .../repo/cloudbrain/models/dir_list.tmpl | 27 +++++++++++++++++ templates/repo/cloudbrain/models/index.tmpl | 29 +++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 templates/repo/cloudbrain/models/dir_list.tmpl create mode 100755 templates/repo/cloudbrain/models/index.tmpl diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index e70944150..4b3162c28 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -25,7 +25,7 @@ const ( tplCloudBrainIndex base.TplName = "repo/cloudbrain/index" tplCloudBrainNew base.TplName = "repo/cloudbrain/new" tplCloudBrainShow base.TplName = "repo/cloudbrain/show" - tplCloudBrainShowModels base.TplName = "repo/cloudbrain/show_models" + tplCloudBrainShowModels base.TplName = "repo/cloudbrain/models/index" ) var ( @@ -365,6 +365,7 @@ func CloudBrainShowModels(ctx *context.Context) { ctx.Data["Dirs"] = fileInfos ctx.Data["task"] = task + ctx.Data["JobID"] = jobID ctx.HTML(200, tplCloudBrainShowModels) } diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 9a58a05a6..f48f063e8 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -248,7 +248,7 @@ -
+
{{.Status}}
@@ -257,11 +257,11 @@ {{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}
- -
+ +
- - 查看 + + 模型下载
diff --git a/templates/repo/cloudbrain/models/dir_list.tmpl b/templates/repo/cloudbrain/models/dir_list.tmpl new file mode 100755 index 000000000..db397f13e --- /dev/null +++ b/templates/repo/cloudbrain/models/dir_list.tmpl @@ -0,0 +1,27 @@ +{{if .Dirs}} + + + {{range .Dirs}} + + + + + + {{end}} + +
+ + + + {{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}} {{.FileName}} + + + + + {{.Size | FileSize}} + + + {{.ModTime}} +
+ +{{end}} diff --git a/templates/repo/cloudbrain/models/index.tmpl b/templates/repo/cloudbrain/models/index.tmpl new file mode 100755 index 000000000..3b53ad78e --- /dev/null +++ b/templates/repo/cloudbrain/models/index.tmpl @@ -0,0 +1,29 @@ +{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+
+
+
+

+ {{ range $index, $item := .Path }}{{ $item }}/{{ end }} +

+
+
+
+ +
+
+
+
+ {{template "repo/cloudbrain/models/dir_list" .}} +
+
+
+
+
+
+ + + +{{template "base/footer" .}} From 153837f1c08457b9d5face3a93b7d1485bffacab Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 17 Jun 2021 11:44:24 +0800 Subject: [PATCH 6/7] show model --- routers/repo/cloudbrain.go | 2 ++ templates/repo/cloudbrain/models/dir_list.tmpl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 4b3162c28..2ea0e98ab 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -340,6 +340,7 @@ func CloudBrainShowModels(ctx *context.Context) { jobID := ctx.Params(":jobid") parentDir := ctx.Query("parentDir") + dirArray := strings.Split(parentDir, "/") task, err := models.GetCloudbrainByJobID(jobID) if err != nil { log.Error("no such job!") @@ -363,6 +364,7 @@ func CloudBrainShowModels(ctx *context.Context) { return } + ctx.Data["Path"] = dirArray ctx.Data["Dirs"] = fileInfos ctx.Data["task"] = task ctx.Data["JobID"] = jobID diff --git a/templates/repo/cloudbrain/models/dir_list.tmpl b/templates/repo/cloudbrain/models/dir_list.tmpl index db397f13e..a9683de77 100755 --- a/templates/repo/cloudbrain/models/dir_list.tmpl +++ b/templates/repo/cloudbrain/models/dir_list.tmpl @@ -6,7 +6,7 @@ - + {{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}} {{.FileName}} From d80fd0c1a22d54f18e10ca6df867a02ef0131031 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Mon, 21 Jun 2021 15:38:14 +0800 Subject: [PATCH 7/7] adjust --- templates/repo/cloudbrain/index.tmpl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index f48f063e8..60ce3c202 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -257,15 +257,6 @@ {{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}
- -
- - - 模型下载 - - -
-
@@ -304,6 +295,15 @@
+ +
+ + + 模型下载 + + +
+ 提交镜像