search.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/model"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func searchAll(c *bm.Context) {
  8. var (
  9. mid int64
  10. buvid string
  11. err error
  12. )
  13. v := new(model.SearchAllArg)
  14. if err = c.Bind(v); err != nil {
  15. return
  16. }
  17. if v.Pn <= 0 {
  18. v.Pn = 1
  19. }
  20. singleColumnStr := c.Request.Form.Get("single_column")
  21. if v.SingleColumn, err = strconv.Atoi(singleColumnStr); err != nil {
  22. v.SingleColumn = -1
  23. }
  24. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  25. buvid = ck.Value
  26. }
  27. if midInter, ok := c.Get("mid"); ok {
  28. mid = midInter.(int64)
  29. }
  30. c.JSON(webSvc.SearchAll(c, mid, v, buvid, c.Request.Header.Get("User-Agent"), ""))
  31. }
  32. func searchByType(c *bm.Context) {
  33. var (
  34. mid int64
  35. buvid string
  36. err error
  37. )
  38. v := new(model.SearchTypeArg)
  39. if err = c.Bind(v); err != nil {
  40. return
  41. }
  42. singleColumnStr := c.Request.Form.Get("single_column")
  43. if v.SingleColumn, err = strconv.Atoi(singleColumnStr); err != nil {
  44. v.SingleColumn = -1
  45. }
  46. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  47. buvid = ck.Value
  48. }
  49. if midInter, ok := c.Get("mid"); ok {
  50. mid = midInter.(int64)
  51. }
  52. c.JSON(webSvc.SearchByType(c, mid, v, buvid, c.Request.Header.Get("User-Agent")))
  53. }
  54. func searchRec(c *bm.Context) {
  55. var (
  56. mid int64
  57. buvid string
  58. err error
  59. )
  60. v := new(struct {
  61. Pn int `form:"page" default:"1" validate:"min=1"`
  62. Ps int `form:"pagesize" default:"5" validate:"min=1"`
  63. Keyword string `form:"keyword"`
  64. FromSource string `form:"from_source"`
  65. })
  66. if err = c.Bind(v); err != nil {
  67. return
  68. }
  69. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  70. buvid = ck.Value
  71. }
  72. if midInter, ok := c.Get("mid"); ok {
  73. mid = midInter.(int64)
  74. }
  75. c.JSON(webSvc.SearchRec(c, mid, v.Pn, v.Ps, v.Keyword, v.FromSource, buvid, c.Request.Header.Get("User-Agent")))
  76. }
  77. func searchDefault(c *bm.Context) {
  78. var (
  79. mid int64
  80. buvid string
  81. err error
  82. )
  83. v := new(struct {
  84. FromSource string `form:"from_source"`
  85. })
  86. if err = c.Bind(v); err != nil {
  87. return
  88. }
  89. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  90. buvid = ck.Value
  91. }
  92. if midInter, ok := c.Get("mid"); ok {
  93. mid = midInter.(int64)
  94. }
  95. c.JSON(webSvc.SearchDefault(c, mid, v.FromSource, buvid, c.Request.Header.Get("User-Agent")))
  96. }
  97. func upRec(c *bm.Context) {
  98. var buvid string
  99. v := new(model.SearchUpRecArg)
  100. if err := c.Bind(v); err != nil {
  101. return
  102. }
  103. midStr, _ := c.Get("mid")
  104. mid := midStr.(int64)
  105. if ck, err := c.Request.Cookie("buvid3"); err == nil {
  106. buvid = ck.Value
  107. }
  108. c.JSON(webSvc.UpRec(c, mid, v, buvid))
  109. }
  110. func searchEgg(c *bm.Context) {
  111. v := new(struct {
  112. EggID int64 `form:"egg_id" validate:"min=1"`
  113. })
  114. if err := c.Bind(v); err != nil {
  115. return
  116. }
  117. c.JSON(webSvc.SearchEgg(c, v.EggID))
  118. }