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.

limit.go 1.3 kB

3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package point
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/context"
  5. "code.gitea.io/gitea/modules/log"
  6. "code.gitea.io/gitea/routers/response"
  7. "code.gitea.io/gitea/services/reward/limiter"
  8. "net/http"
  9. )
  10. func GetSingleDailyPointLimitConfig(ctx *context.Context) {
  11. r, err := limiter.GetSingleDailyPointLimitConfig()
  12. if err != nil {
  13. ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
  14. return
  15. }
  16. resultMap := make(map[string]interface{}, 0)
  17. if r == nil {
  18. resultMap["LimitNum"] = ""
  19. } else {
  20. resultMap["LimitNum"] = r.LimitNum
  21. }
  22. ctx.JSON(http.StatusOK, response.SuccessWithData(resultMap))
  23. }
  24. func SetSingleDailyPointLimitConfig(ctx *context.Context, config models.LimitConfigVO) {
  25. err := limiter.SetSingleDailyPointLimitConfig(config.LimitNum, ctx.User)
  26. if err != nil {
  27. log.Error("Set single daily point limit config error. %v", err)
  28. ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
  29. return
  30. }
  31. ctx.JSON(http.StatusOK, response.Success())
  32. }
  33. func DeletePointLimitConfig(ctx *context.Context) {
  34. id := ctx.QueryInt64("id")
  35. err := limiter.DeleteLimitConfig(id, ctx.User)
  36. if err != nil {
  37. ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
  38. return
  39. }
  40. ctx.JSON(http.StatusOK, response.Success())
  41. }