|
|
|
@@ -118,6 +118,11 @@ func SaveModel(ctx *context.Context) { |
|
|
|
label := ctx.Query("Label") |
|
|
|
description := ctx.Query("Description") |
|
|
|
|
|
|
|
if !ctx.Repo.CanWrite(models.UnitTypeCloudBrain) { |
|
|
|
ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if JobId == "" || VersionName == "" { |
|
|
|
ctx.Error(500, fmt.Sprintf("JobId or VersionName is null.")) |
|
|
|
return |
|
|
|
@@ -164,7 +169,7 @@ func downloadModelFromCloudBrainTwo(modelUUID string, jobName string, parentDir |
|
|
|
func DeleteModel(ctx *context.Context) { |
|
|
|
log.Info("delete model start.") |
|
|
|
id := ctx.Query("ID") |
|
|
|
err := DeleteModelByID(id) |
|
|
|
err := deleteModelByID(ctx, id) |
|
|
|
if err != nil { |
|
|
|
ctx.JSON(500, err.Error()) |
|
|
|
} else { |
|
|
|
@@ -173,11 +178,22 @@ func DeleteModel(ctx *context.Context) { |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
func isCanDeleteOrDownload(ctx *context.Context, model *models.AiModelManage) bool { |
|
|
|
if ctx.User.IsAdmin || ctx.User.ID == model.UserId { |
|
|
|
return true |
|
|
|
} |
|
|
|
if ctx.Repo.IsOwner() { |
|
|
|
return true |
|
|
|
} |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
func DeleteModelByID(id string) error { |
|
|
|
func deleteModelByID(ctx *context.Context, id string) error { |
|
|
|
log.Info("delete model start. id=" + id) |
|
|
|
|
|
|
|
model, err := models.QueryModelById(id) |
|
|
|
if !isCanDeleteOrDownload(ctx, model) { |
|
|
|
return errors.New(ctx.Tr("repo.model_noright")) |
|
|
|
} |
|
|
|
if err == nil { |
|
|
|
log.Info("bucket=" + setting.Bucket + " path=" + model.Path) |
|
|
|
if strings.HasPrefix(model.Path, setting.Bucket+"/"+Model_prefix) { |
|
|
|
@@ -224,6 +240,11 @@ func DownloadMultiModelFile(ctx *context.Context) { |
|
|
|
ctx.ServerError("no such model:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
if !isCanDeleteOrDownload(ctx, task) { |
|
|
|
ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright"))) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
path := Model_prefix + models.AttachmentRelativePath(id) + "/" |
|
|
|
|
|
|
|
allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path) |
|
|
|
@@ -381,9 +402,23 @@ func ShowModelTemplate(ctx *context.Context) { |
|
|
|
ctx.HTML(200, tplModelManageIndex) |
|
|
|
} |
|
|
|
|
|
|
|
func isQueryRight(ctx *context.Context) bool { |
|
|
|
if ctx.Repo.Repository.IsPrivate { |
|
|
|
if ctx.User.IsAdmin || ctx.Repo.IsAdmin() || ctx.Repo.IsOwner() { |
|
|
|
return true |
|
|
|
} |
|
|
|
return false |
|
|
|
} else { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func ShowModelPageInfo(ctx *context.Context) { |
|
|
|
log.Info("ShowModelInfo start.") |
|
|
|
|
|
|
|
if !isQueryRight(ctx) { |
|
|
|
ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright"))) |
|
|
|
return |
|
|
|
} |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
|