Browse Source

Merge branch 'file-notebook' of openi.pcl.ac.cn:OpenI/aiforge into file-notebook

tags/v1.22.11.3^2
zhoupzh 3 years ago
parent
commit
59a6531c53
1 changed files with 8 additions and 9 deletions
  1. +8
    -9
      modules/modelarts/modelarts.go

+ 8
- 9
modules/modelarts/modelarts.go View File

@@ -11,8 +11,6 @@ import (
"strconv"
"strings"

"github.com/go-resty/resty/v2"

"code.gitea.io/gitea/modules/cloudbrain"

"code.gitea.io/gitea/modules/modelarts_cd"
@@ -932,8 +930,8 @@ func HandleNotebookInfo(task *models.Cloudbrain) error {

func uploadNoteBookFile(task *models.Cloudbrain, result *models.GetNotebook2Result) {
jupyterUrl := result.Url + "?token=" + result.Token
client := getRestyClient()
cookies, xsrf := getCookiesAndCsrf(client, jupyterUrl)
cookies, xsrf := getCookiesAndCsrf(jupyterUrl)
if xsrf == "" {
log.Error("browser jupyterUrl failed:%v", task.DisplayJobName)
} else {
@@ -945,7 +943,7 @@ func uploadNoteBookFile(task *models.Cloudbrain, result *models.GetNotebook2Resu
}

base64Content := base64.StdEncoding.EncodeToString(fileContents)
client := getRestyClient()
uploadUrl := getJupyterBaseUrl(result.Url) + "api/contents/" + path.Base(task.BootFile)
res, err := client.R().
SetCookies(cookies).
@@ -973,11 +971,11 @@ func getJupyterBaseUrl(url string) string {
return baseUrl
}

func getCookiesAndCsrf(client *resty.Client, jupyterUrl string) ([]*http.Cookie, string) {
func getCookiesAndCsrf(jupyterUrl string) ([]*http.Cookie, string) {
log.Info("jupyter url:"+jupyterUrl)
var cookies []*http.Cookie
for i := 0; i < 4; i++ {
res, err := client.R().Get(jupyterUrl)
for i := 0; i < 10; i++ {
res, err := http.Get(jupyterUrl)
if err != nil {
log.Error("browser jupyterUrl failed.")
return cookies, ""
@@ -987,6 +985,7 @@ func getCookiesAndCsrf(client *resty.Client, jupyterUrl string) ([]*http.Cookie,
for _, cookie := range cookies {
if cookie.Name == "_xsrf" {
xsrf = cookie.Value
break
}

}


Loading…
Cancel
Save