search.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-intl/model"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. const _keyWordLen = 50
  10. func searchAll(c *bm.Context) {
  11. var (
  12. build int
  13. mid int64
  14. pn, ps int
  15. err error
  16. )
  17. params := c.Request.Form
  18. header := c.Request.Header
  19. // params
  20. mobiApp := params.Get("mobi_app")
  21. device := params.Get("device")
  22. ridStr := params.Get("rid")
  23. keyword := params.Get("keyword")
  24. highlightStr := params.Get("highlight")
  25. lang := params.Get("lang")
  26. duration := params.Get("duration")
  27. order := params.Get("order")
  28. filtered := params.Get("filtered")
  29. platform := params.Get("platform")
  30. zoneidStr := params.Get("zoneid")
  31. fromSource := params.Get("from_source")
  32. recommend := params.Get("recommend")
  33. // header
  34. buvid := header.Get("Buvid")
  35. // check params
  36. if keyword == "" || len([]rune(keyword)) > _keyWordLen {
  37. c.JSON(nil, ecode.RequestErr)
  38. return
  39. }
  40. if build, err = strconv.Atoi(params.Get("build")); err != nil {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. zoneid, _ := strconv.ParseInt(zoneidStr, 10, 64)
  45. rid, _ := strconv.Atoi(ridStr)
  46. highlight, _ := strconv.Atoi(highlightStr)
  47. // page and size
  48. if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
  49. pn = 1
  50. }
  51. if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
  52. ps = 20
  53. }
  54. if midInter, ok := c.Get("mid"); ok {
  55. mid = midInter.(int64)
  56. }
  57. switch order {
  58. case "default", "":
  59. order = "totalrank"
  60. case "view":
  61. order = "click"
  62. case "danmaku":
  63. order = "dm"
  64. }
  65. if duration == "" {
  66. duration = "0"
  67. }
  68. if recommend == "" || recommend != "1" {
  69. recommend = "0"
  70. }
  71. plat := model.Plat(mobiApp, device)
  72. c.JSON(searchSvc.Search(c, mid, zoneid, mobiApp, device, platform, buvid, keyword, duration, order, filtered, lang, fromSource, recommend, plat, rid, highlight, build, pn, ps, time.Now()))
  73. }
  74. func searchByType(c *bm.Context) {
  75. var (
  76. build int
  77. mid int64
  78. pn, ps int
  79. typeV string
  80. err error
  81. )
  82. params := c.Request.Form
  83. header := c.Request.Header
  84. // params
  85. mobiApp := params.Get("mobi_app")
  86. device := params.Get("device")
  87. sType := params.Get("type")
  88. keyword := params.Get("keyword")
  89. filtered := params.Get("filtered")
  90. zoneidStr := params.Get("zoneid")
  91. order := params.Get("order")
  92. platform := params.Get("platform")
  93. highlightStr := params.Get("highlight")
  94. categoryIDStr := params.Get("category_id")
  95. userTypeStr := params.Get("user_type")
  96. orderSortStr := params.Get("order_sort")
  97. // header
  98. buvid := header.Get("Buvid")
  99. if keyword == "" || len([]rune(keyword)) > _keyWordLen {
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. if build, err = strconv.Atoi(params.Get("build")); err != nil {
  104. c.JSON(nil, ecode.RequestErr)
  105. return
  106. }
  107. userType, _ := strconv.Atoi(userTypeStr)
  108. orderSort, _ := strconv.Atoi(orderSortStr)
  109. zoneid, _ := strconv.ParseInt(zoneidStr, 10, 64)
  110. categoryID, _ := strconv.Atoi(categoryIDStr)
  111. highlight, _ := strconv.Atoi(highlightStr)
  112. // page and size
  113. if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
  114. pn = 1
  115. }
  116. if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 20 {
  117. ps = 20
  118. }
  119. if midInter, ok := c.Get("mid"); ok {
  120. mid = midInter.(int64)
  121. }
  122. switch sType {
  123. case "2":
  124. typeV = "upper"
  125. case "6":
  126. typeV = "article"
  127. case "7":
  128. typeV = "season2"
  129. case "8":
  130. typeV = "movie2"
  131. case "9":
  132. typeV = "tag"
  133. }
  134. plat := model.Plat(mobiApp, device)
  135. c.JSON(searchSvc.SearchByType(c, mid, zoneid, mobiApp, device, platform, buvid, typeV, keyword, filtered, order, plat, build, highlight, categoryID, userType, orderSort, pn, ps, time.Now()))
  136. }
  137. // suggest3 search suggest data from newest api.
  138. func suggest3(c *bm.Context) {
  139. var (
  140. build int
  141. mid int64
  142. err error
  143. )
  144. params := c.Request.Form
  145. header := c.Request.Header
  146. mobiApp := params.Get("mobi_app")
  147. term := params.Get("keyword")
  148. highlight, _ := strconv.Atoi(params.Get("highlight"))
  149. if midInter, ok := c.Get("mid"); ok {
  150. mid = midInter.(int64)
  151. }
  152. if build, err = strconv.Atoi(params.Get("build")); err != nil {
  153. c.JSON(nil, ecode.RequestErr)
  154. return
  155. }
  156. buvid := header.Get(_headerBuvid)
  157. platform := params.Get("platform")
  158. c.JSON(searchSvc.Suggest3(c, mid, platform, buvid, term, build, highlight, mobiApp, time.Now()), nil)
  159. }