From 62b8bf1290d8b4cd193a571ba217d374e054db14 Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 3 Dec 2021 17:07:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- options/locale/locale_en-US.ini | 2 ++ routers/repo/ai_model_manage.go | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a61b47428..f2f1d29d8 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -883,6 +883,8 @@ modelarts.train_job_para_admin=train_job_para_admin modelarts.train_job_para.edit=train_job_para.edit modelarts.train_job_para.connfirm=train_job_para.connfirm +model.manage.create_error=Equal Name and Version has existed. + template.items = Template Items template.git_content = Git Content (Default Branch) template.git_hooks = Git Hooks diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 1ab0bbbe5..833c41c14 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -26,7 +26,7 @@ const ( MODEL_NOT_LATEST = 0 ) -func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, userId int64, userName string, userHeadUrl string) error { +func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, ctx *context.Context) error { aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName) //aiTask, err := models.GetCloudbrainByJobID(jobId) if err != nil { @@ -45,6 +45,9 @@ func saveModelByParameters(jobId string, versionName string, name string, versio aimodels := models.QueryModelByName(name, aiTask.RepoID) if len(aimodels) > 0 { for _, model := range aimodels { + if model.Version == version { + return errors.New(ctx.Tr("repo.model.manage.create_error")) + } if model.New == MODEL_LATEST { lastNewModelId = model.ID } @@ -82,9 +85,9 @@ func saveModelByParameters(jobId string, versionName string, name string, versio Size: modelSize, AttachmentId: aiTask.Uuid, RepoId: aiTask.RepoID, - UserId: userId, - UserName: userName, - UserRelAvatarLink: userHeadUrl, + UserId: ctx.User.ID, + UserName: ctx.User.Name, + UserRelAvatarLink: ctx.User.RelAvatarLink(), CodeBranch: aiTask.BranchName, CodeCommitID: aiTask.CommitID, Engine: aiTask.EngineID, @@ -125,7 +128,7 @@ func SaveModel(ctx *context.Context) { return } - err := saveModelByParameters(JobId, VersionName, name, version, label, description, ctx.User.ID, ctx.User.Name, ctx.User.RelAvatarLink()) + err := saveModelByParameters(JobId, VersionName, name, version, label, description, ctx) if err != nil { log.Info("save model error." + err.Error()) @@ -355,7 +358,7 @@ func ShowModelInfo(ctx *context.Context) { } func ShowSingleModel(ctx *context.Context) { - id := ctx.Params(":ID") + id := ctx.Query("ID") parentDir := ctx.Query("parentDir") log.Info("Show single ModelInfo start.id=" + id) task, err := models.QueryModelById(id)