From 346b5d9c3fa14a7458f89e2f1fc3c4372a051bcf Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 24 Aug 2021 19:31:23 +0800 Subject: [PATCH] no require dataset --- modules/auth/modelarts.go | 2 +- modules/modelarts/modelarts.go | 30 +++++++++++++++++++++++++----- modules/setting/setting.go | 11 ++++++----- modules/storage/obs.go | 14 ++++++++++++++ templates/repo/modelarts/new.tmpl | 7 ++++--- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/modules/auth/modelarts.go b/modules/auth/modelarts.go index 11a3bc562..0be3e3882 100755 --- a/modules/auth/modelarts.go +++ b/modules/auth/modelarts.go @@ -7,7 +7,7 @@ import ( type CreateModelArtsForm struct { JobName string `form:"job_name" binding:"Required"` - Attachment string `form:"attachment" binding:"Required"` + Attachment string `form:"attachment"` Description string `form:"description"` } diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index a5cb8388b..edd9d5d6b 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -1,13 +1,13 @@ package modelarts import ( - "code.gitea.io/gitea/modules/setting" - "encoding/json" - "path" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/storage" + "encoding/json" + "path" ) const ( @@ -25,7 +25,27 @@ var ( ) func GenerateTask(ctx *context.Context, jobName, uuid, description string) error { - dataActualPath := setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/" + var dataActualPath string + if uuid != "" { + dataActualPath = setting.Bucket + "/" + setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/" + } else { + userPath := setting.UserBasePath + ctx.User.Name + "/" + isExist, err := storage.ObsHasObject(userPath) + if err != nil { + log.Error("ObsHasObject failed:%v", err.Error(), ctx.Data["MsgID"]) + return err + } + + if !isExist { + if err = storage.ObsCreateObject(userPath); err != nil { + log.Error("ObsCreateObject failed:%v", err.Error(), ctx.Data["MsgID"]) + return err + } + } + + dataActualPath = setting.Bucket + "/" + userPath + } + if poolInfos == nil { json.Unmarshal([]byte(setting.PoolInfos), &poolInfos) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 142369f88..687f02605 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -463,7 +463,7 @@ var ( Bucket string Location string BasePath string - //RealPath string + UserBasePath string //modelarts config ModelArtsHost string @@ -473,10 +473,10 @@ var ( ModelArtsUsername string ModelArtsPassword string ModelArtsDomain string - ProfileID string - PoolInfos string - Flavor string - FlavorInfos string + ProfileID string + PoolInfos string + Flavor string + FlavorInfos string ) // DateLang transforms standard language locale name to corresponding value in datetime plugin. @@ -1177,6 +1177,7 @@ func NewContext() { Bucket = sec.Key("BUCKET").MustString("testopendata") Location = sec.Key("LOCATION").MustString("cn-south-222") BasePath = sec.Key("BASE_PATH").MustString("attachment/") + UserBasePath = sec.Key("BASE_PATH_USER").MustString("users/") sec = Cfg.Section("modelarts") ModelArtsHost = sec.Key("ENDPOINT").MustString("112.95.163.80") diff --git a/modules/storage/obs.go b/modules/storage/obs.go index b4de303cf..77fe49b4e 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -143,3 +143,17 @@ func ObsGetPreSignedUrl(uuid, fileName string) (string, error) { return output.SignedUrl, nil } + +func ObsCreateObject(path string) error { + input := &obs.PutObjectInput{} + input.Bucket = setting.Bucket + input.Key = path + + _, err := ObsCli.PutObject(input) + if err != nil { + log.Error("PutObject failed:", err.Error()) + return err + } + + return nil +} diff --git a/templates/repo/modelarts/new.tmpl b/templates/repo/modelarts/new.tmpl index c77a1fe47..5664de181 100755 --- a/templates/repo/modelarts/new.tmpl +++ b/templates/repo/modelarts/new.tmpl @@ -112,14 +112,15 @@ -
+
- + {{range .attachments}} {{end}} - +