From e889e6141626f282effdce6dde898fe73e8fbf0f Mon Sep 17 00:00:00 2001 From: Gitea Date: Tue, 26 Oct 2021 20:07:03 +0800 Subject: [PATCH] add status, duration and modelDownload --- routers/repo/cloudbrain.go | 29 ++++++++++++++++++++++------- routers/routes/routes.go | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 648061171..803f2a4ec 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -98,15 +98,15 @@ func cutString(str string, lens int) string { func jobNamePrefixValid(s string) string { lowStr := strings.ToLower(s) re := regexp.MustCompile(`[^a-z0-9_\\-]+`) - + removeSpecial := re.ReplaceAllString(lowStr, "") - + re = regexp.MustCompile(`^[_\\-]+`) return re.ReplaceAllString(removeSpecial, "") } -func cloudBrainNewDataPrepare(ctx *context.Context) error{ +func cloudBrainNewDataPrepare(ctx *context.Context) error { ctx.Data["PageIsCloudBrain"] = true t := time.Now() var jobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:] @@ -556,6 +556,21 @@ func CloudBrainDownloadModel(ctx *context.Context) { http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) } +func TrainJobloadModel(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.Data["msgID"]) + 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) @@ -579,9 +594,9 @@ func downloadCode(repo *models.Repository, codePath string) error { return err } - configFile, err := os.OpenFile(codePath + "/.git/config", os.O_RDWR, 0666) + configFile, err := os.OpenFile(codePath+"/.git/config", os.O_RDWR, 0666) if err != nil { - log.Error("open file(%s) failed:%v", codePath + "/,git/config", err) + log.Error("open file(%s) failed:%v", codePath+"/,git/config", err) return err } @@ -601,10 +616,10 @@ func downloadCode(repo *models.Repository, codePath string) error { } } - if strings.Contains(line, "url") && strings.Contains(line, ".git"){ + if strings.Contains(line, "url") && strings.Contains(line, ".git") { originUrl := "\turl = " + repo.CloneLink().HTTPS + "\n" if len(line) > len(originUrl) { - originUrl += strings.Repeat( " ", len(line) - len(originUrl)) + originUrl += strings.Repeat(" ", len(line)-len(originUrl)) } bytes := []byte(originUrl) _, err := configFile.WriteAt(bytes, pos) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 0a3bf633a..878868d6d 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -994,6 +994,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/create", reqRepoCloudBrainReader, repo.TrainJobNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsTrainJobForm{}), repo.TrainJobCreate) m.Get("/para-config-list", reqRepoCloudBrainReader, repo.TrainJobGetConfigList) + m.Get("/download_model", reqRepoCloudBrainReader, repo.TrainJobloadModel) }) }, context.RepoRef())