@@ -949,7 +949,7 @@ func ShowModelInfo(ctx *context.Context) {
ctx.HTML(200, tplModelInfo)
}
func QueryModelById(ctx *context.Context) {
func QueryModelObj ById(ctx *context.Context) *models.AiModelManage {
id := ctx.Query("id")
model, err := models.QueryModelById(id)
if err == nil {
@@ -957,13 +957,22 @@ func QueryModelById(ctx *context.Context) {
model.IsCanDelete = isCanDelete(ctx, model.UserId)
model.IsCanDownload = isCanDownload(ctx, model)
removeIpInfo(model)
return model
} else {
return nil
}
}
func QueryModelById(ctx *context.Context) {
model := QueryModelObjById(ctx)
if model != nil {
ctx.JSON(http.StatusOK, model)
} else {
ctx.JSON(http.StatusNotFound, nil)
}
}
func ShowSingleModel(ctx *context.Context) {
func QueryModelObjByName(ctx *context.Context) []*models.AiModelManage {
name := ctx.Query("name")
log.Info("Show single ModelInfo start.name=" + name)
modelArrays := models.QueryModelByName(name, ctx.Repo.Repository.ID)
@@ -1004,8 +1013,11 @@ func ShowSingleModel(ctx *context.Context) {
model.UserRelAvatarLink = value.RelAvatarLink()
}
}
return modelResult
}
ctx.JSON(http.StatusOK, modelResult)
func ShowSingleModel(ctx *context.Context) {
ctx.JSON(http.StatusOK, QueryModelObjByName(ctx))
}
func removeIpInfo(model *models.AiModelManage) {
@@ -1172,6 +1184,8 @@ func isAdminRight(ctx *context.Context) bool {
if err != nil {
log.Error("GetUserRepoPermission failed:%v", err.Error())
return false
} else {
log.Info("permission.AccessMode=" + string(permission.AccessMode))
}
if permission.AccessMode >= models.AccessModeAdmin {
return true
@@ -1181,6 +1195,7 @@ func isAdminRight(ctx *context.Context) bool {
func isOperModifyOrDelete(ctx *context.Context, modelUserId int64) bool {
if ctx.User == nil {
log.Info("user is nil")
return false
}
if ctx.User.IsAdmin || ctx.User.ID == modelUserId {
@@ -1189,6 +1204,10 @@ func isOperModifyOrDelete(ctx *context.Context, modelUserId int64) bool {
return isAdminRight(ctx)
}
func IsOperModifyOrDelete(ctx *context.Context, modelUserId int64) bool {
return isOperModifyOrDelete(ctx, modelUserId)
}
func ShowModelPageInfo(ctx *context.Context) {
log.Info("ShowModelInfo start.")
if !isQueryRight(ctx) {