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 8d8e97377..2ea0e98ab 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" @@ -23,6 +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/models/index" ) var ( @@ -332,6 +335,69 @@ func CloudBrainDel(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") } +func CloudBrainShowModels(ctx *context.Context) { + ctx.Data["PageIsCloudBrain"] = true + + 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!") + 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["Path"] = dirArray + ctx.Data["Dirs"] = fileInfos + ctx.Data["task"] = task + ctx.Data["JobID"] = jobID + ctx.HTML(200, tplCloudBrainShowModels) +} + +func getModelDirs(jobName string, parentDir string) (string, error) { + var req string + modelActualPath := setting.JobPath + jobName + "/model/" + if parentDir == "" { + req = "baseDir=" + modelActualPath + } else { + req = "baseDir=" + modelActualPath + "&parentDir=" + parentDir + } + + return getDirs(req) +} + +func CloudBrainDownloadModel(ctx *context.Context) { + 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()) + 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/repo/dir.go b/routers/repo/dir.go index 388af34ec..d1dfbcd11 100755 --- a/routers/repo/dir.go +++ b/routers/repo/dir.go @@ -58,10 +58,10 @@ 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) + log.Error("getDatasetDirs failed:", err.Error()) + ctx.ServerError("getDatasetDirs failed:", err) return } @@ -75,20 +75,31 @@ 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 + 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) +} + +func getDirs(req string) (string, error) { + var dirs string + url := setting.DecompressAddress + "/dirs?" + req reqHttp, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { @@ -127,6 +138,5 @@ func getDirs(uuid string, parentDir string) (string, error) { } dirs = resp.FileInfos - return dirs, nil } 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()) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index 9a58a05a6..60ce3c202 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -248,7 +248,7 @@ -
+
{{.Status}}
@@ -257,15 +257,6 @@ {{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}
- -
- - - 查看 - - -
-
@@ -304,6 +295,15 @@
+ +
+ + + 模型下载 + + +
+ 提交镜像 diff --git a/templates/repo/cloudbrain/models/dir_list.tmpl b/templates/repo/cloudbrain/models/dir_list.tmpl new file mode 100755 index 000000000..a9683de77 --- /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" .}} diff --git a/templates/repo/datasets/dirs/dir_list.tmpl b/templates/repo/datasets/dirs/dir_list.tmpl index 98232e17e..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}}