You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.go 902 B

3 years ago
1234567891011121314151617181920212223242526272829303132333435
  1. package image
  2. import (
  3. "code.gitea.io/gitea/modules/notification"
  4. "net/http"
  5. "strconv"
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/context"
  8. )
  9. func Action(ctx *context.Context) {
  10. var err error
  11. imageId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64)
  12. switch ctx.Params(":action") {
  13. case "star":
  14. err = models.StarImage(ctx.User.ID, imageId, true)
  15. case "unstar":
  16. err = models.StarImage(ctx.User.ID, imageId, false)
  17. case "recommend":
  18. err = models.RecommendImage(imageId, true)
  19. case "unrecommend":
  20. err = models.RecommendImage(imageId, false)
  21. }
  22. if err != nil {
  23. ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.star_fail", ctx.Params(":action"))))
  24. } else {
  25. image, err := models.GetImageByID(imageId)
  26. if err == nil {
  27. notification.NotifyImageRecommend(ctx.User, image, ctx.Params(":action"))
  28. }
  29. ctx.JSON(http.StatusOK, models.BaseOKMessage)
  30. }
  31. }