From f660adede03bd61ad9087b4d882156e1bbbcf212 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Fri, 18 Nov 2022 17:17:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/modelarts/modelarts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index 1b4d093a1..2b54d797e 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -976,8 +976,8 @@ func getJupyterBaseUrl(url string) string { func getCookiesAndCsrf(client *resty.Client, jupyterUrl string) ([]*http.Cookie, string) { var cookies []*http.Cookie - for i := 0; i < 4; i++ { - res, err := client.R().Get(jupyterUrl) + for i := 0; i < 10; i++ { + res, err := client.R().SetCookies(cookies).Get(jupyterUrl) if err != nil { log.Error("browser jupyterUrl failed.") return cookies, "" From c34d42b07dd3e90f89fa82550de9400d914a0ec5 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Fri, 18 Nov 2022 18:09:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/modelarts/modelarts.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index 2b54d797e..acbe8947f 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -974,10 +974,10 @@ func getJupyterBaseUrl(url string) string { } func getCookiesAndCsrf(client *resty.Client, jupyterUrl string) ([]*http.Cookie, string) { - + log.Info("jupyter url:"+jupyterUrl) var cookies []*http.Cookie for i := 0; i < 10; i++ { - res, err := client.R().SetCookies(cookies).Get(jupyterUrl) + res, err := http.Get(jupyterUrl) if err != nil { log.Error("browser jupyterUrl failed.") return cookies, "" @@ -987,6 +987,7 @@ func getCookiesAndCsrf(client *resty.Client, jupyterUrl string) ([]*http.Cookie, for _, cookie := range cookies { if cookie.Name == "_xsrf" { xsrf = cookie.Value + break } } From 77ac02cfe9b1aa12bdc4b9d4db87d65dbed6fe35 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Mon, 21 Nov 2022 08:50:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/modelarts/modelarts.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index acbe8947f..4681c18d5 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -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,7 +971,7 @@ 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 < 10; i++ {