res.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package http
  2. import (
  3. "strconv"
  4. rsmdl "go-common/app/interface/main/web-show/model/resource"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. const (
  10. _headerBuvid = "Buvid"
  11. _buvid = "buvid3"
  12. )
  13. func resources(c *bm.Context) {
  14. arg := new(rsmdl.ArgRess)
  15. if err := c.Bind(arg); err != nil {
  16. return
  17. }
  18. arg.Mid, arg.Sid, arg.Buvid = device(c)
  19. data, count, err := resSvc.Resources(c, arg)
  20. if err != nil {
  21. log.Error("resSvc.Resource error(%v)", err)
  22. c.JSON(nil, ecode.Degrade)
  23. return
  24. }
  25. c.JSONMap(map[string]interface{}{
  26. "count": count,
  27. "data": data,
  28. }, nil)
  29. }
  30. func resource(c *bm.Context) {
  31. arg := new(rsmdl.ArgRes)
  32. if err := c.Bind(arg); err != nil {
  33. return
  34. }
  35. arg.Mid, arg.Sid, arg.Buvid = device(c)
  36. data, count, err := resSvc.Resource(c, arg)
  37. if err != nil {
  38. log.Error("resSvc.Resource error(%v)", err)
  39. c.JSON(nil, ecode.Degrade)
  40. return
  41. }
  42. c.JSONMap(map[string]interface{}{
  43. "count": count,
  44. "data": data,
  45. }, nil)
  46. }
  47. func relation(c *bm.Context) {
  48. arg := new(rsmdl.ArgAid)
  49. if err := c.Bind(arg); err != nil {
  50. return
  51. }
  52. arg.Mid, arg.Sid, arg.Buvid = device(c)
  53. c.JSON(resSvc.Relation(c, arg))
  54. }
  55. func advideo(c *bm.Context) {
  56. arg := new(rsmdl.ArgAid)
  57. if err := c.Bind(arg); err != nil {
  58. return
  59. }
  60. midTemp, ok := c.Get("mid")
  61. if !ok {
  62. log.Info("mid not exist")
  63. arg.Mid = 0
  64. } else {
  65. arg.Mid = midTemp.(int64)
  66. }
  67. c.JSON(resSvc.VideoAd(c, arg), nil)
  68. }
  69. func urlMonitor(c *bm.Context) {
  70. params := c.Request.Form
  71. pfStr := params.Get("pf")
  72. pf, _ := strconv.Atoi(pfStr)
  73. c.JSON(resSvc.URLMonitor(c, pf), nil)
  74. }
  75. func device(c *bm.Context) (mid int64, sid, buvid string) {
  76. midTemp, ok := c.Get("mid")
  77. buvid = c.Request.Header.Get(_headerBuvid)
  78. if buvid == "" {
  79. cookie, _ := c.Request.Cookie(_buvid)
  80. if cookie != nil {
  81. buvid = cookie.Value
  82. }
  83. }
  84. if !ok {
  85. if sidCookie, err := c.Request.Cookie("sid"); err == nil {
  86. sid = sidCookie.Value
  87. }
  88. } else {
  89. mid = midTemp.(int64)
  90. }
  91. return
  92. }