Browse Source

add status, duration and modelDownload

tags/v1.21.12.1
Gitea 4 years ago
parent
commit
e889e61416
2 changed files with 23 additions and 7 deletions
  1. +22
    -7
      routers/repo/cloudbrain.go
  2. +1
    -0
      routers/routes/routes.go

+ 22
- 7
routers/repo/cloudbrain.go View File

@@ -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)


+ 1
- 0
routers/routes/routes.go View File

@@ -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())



Loading…
Cancel
Save