package image import ( "code.gitea.io/gitea/modules/notification" "net/http" "strconv" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" ) func Action(ctx *context.Context) { var err error imageId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) switch ctx.Params(":action") { case "star": err = models.StarImage(ctx.User.ID, imageId, true) case "unstar": err = models.StarImage(ctx.User.ID, imageId, false) case "recommend": err = models.RecommendImage(imageId, true) case "unrecommend": err = models.RecommendImage(imageId, false) } if err != nil { ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.star_fail", ctx.Params(":action")))) } else { image, err := models.GetImageByID(imageId) if err == nil { notification.NotifyImageRecommend(ctx.User, image, ctx.Params(":action")) } ctx.JSON(http.StatusOK, models.BaseOKMessage) } }