comment.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package http
  2. import (
  3. v1 "go-common/app/interface/bbq/app-bbq/api/http/v1"
  4. "go-common/app/interface/bbq/app-bbq/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "github.com/pkg/errors"
  8. )
  9. var (
  10. cmType int64
  11. cmID int64
  12. )
  13. func commentInit(c *bm.Context) {
  14. if cmType = cfg.Comment.Type; cmType == 0 {
  15. cmType = model.DefaultCmType
  16. }
  17. //debug conf
  18. if deid := cfg.Comment.DebugID; deid > 0 {
  19. cmID = deid
  20. }
  21. }
  22. func commentCursor(c *bm.Context) {
  23. dev, _ := c.Get("device")
  24. mid, _ := c.Get("mid")
  25. arg := &v1.CommentCursorReq{}
  26. if err := c.Bind(arg); err != nil {
  27. errors.Wrap(err, "参数验证失败")
  28. return
  29. }
  30. device := dev.(*bm.Device)
  31. if mid != nil {
  32. arg.MID = mid.(int64)
  33. } else {
  34. arg.MID = 0
  35. }
  36. //评论区类型overwrite
  37. arg.Type = cmType
  38. if cmID > 0 {
  39. arg.SvID = cmID
  40. }
  41. c.JSON(srv.CommentCursor(c, arg, device))
  42. }
  43. func commentAdd(c *bm.Context) {
  44. dev, _ := c.Get("device")
  45. arg := &v1.CommentAddReq{}
  46. if err := c.Bind(arg); err != nil {
  47. errors.Wrap(err, "参数验证失败")
  48. return
  49. }
  50. if len([]rune(arg.Message)) > 96 {
  51. err := ecode.CommentLengthIllegal
  52. c.JSON(nil, err)
  53. return
  54. }
  55. device := dev.(*bm.Device)
  56. arg.AccessKey = c.Request.Form.Get("access_key")
  57. arg.Type = cmType
  58. if cmID > 0 {
  59. arg.SvID = cmID
  60. }
  61. midVal, _ := c.Get("mid")
  62. resp, err := srv.CommentAdd(c, midVal.(int64), arg, device)
  63. c.JSON(resp, err)
  64. // 埋点
  65. if err != nil {
  66. return
  67. }
  68. ext := &struct {
  69. SVID int64
  70. Root int64
  71. Parent int64
  72. Type int64
  73. }{
  74. SVID: arg.SvID,
  75. Root: arg.Root,
  76. Parent: arg.Parent,
  77. Type: arg.Type,
  78. }
  79. uiLog(c, model.ActionCommentAdd, ext)
  80. }
  81. func commentLike(c *bm.Context) {
  82. dev, _ := c.Get("device")
  83. arg := &v1.CommentLikeReq{}
  84. if err := c.Bind(arg); err != nil {
  85. errors.Wrap(err, "参数验证失败")
  86. return
  87. }
  88. arg.AccessKey = c.Request.Form.Get("access_key")
  89. device := dev.(*bm.Device)
  90. arg.Type = cmType
  91. if cmID > 0 {
  92. arg.SvID = cmID
  93. }
  94. mid, _ := c.Get("mid")
  95. err := srv.CommentLike(c, mid.(int64), arg, device)
  96. c.JSON(nil, err)
  97. // 埋点
  98. if err != nil {
  99. return
  100. }
  101. ext := &struct {
  102. SVID int64
  103. RPID int64
  104. Action int16
  105. Type int64
  106. }{
  107. SVID: arg.SvID,
  108. RPID: arg.RpID,
  109. Action: arg.Action,
  110. Type: arg.Type,
  111. }
  112. uiLog(c, model.ActionCommentLike, ext)
  113. }
  114. func commentList(c *bm.Context) {
  115. dev, _ := c.Get("device")
  116. mid, _ := c.Get("mid")
  117. arg := &v1.CommentListReq{}
  118. if err := c.Bind(arg); err != nil {
  119. errors.Wrap(err, "参数验证失败")
  120. return
  121. }
  122. device := dev.(*bm.Device)
  123. if mid != nil {
  124. arg.MID = mid.(int64)
  125. } else {
  126. arg.MID = 0
  127. }
  128. arg.Type = cmType
  129. if cmID > 0 {
  130. arg.SvID = cmID
  131. }
  132. // 这里是转换成评论那边的平台
  133. if device.RawPlatform == "ios" {
  134. arg.Plat = 3
  135. } else if device.RawPlatform == "android" {
  136. arg.Plat = 2
  137. arg.Pn++
  138. }
  139. c.JSON(srv.CommentList(c, arg, device))
  140. }
  141. func commentSubCursor(c *bm.Context) {
  142. dev, _ := c.Get("device")
  143. arg := &v1.CommentSubCursorReq{}
  144. if err := c.Bind(arg); err != nil {
  145. errors.Wrap(err, "参数验证失败")
  146. return
  147. }
  148. device := dev.(*bm.Device)
  149. arg.Type = cmType
  150. if cmID > 0 {
  151. arg.SvID = cmID
  152. }
  153. var mid int64
  154. midValue, _ := c.Get("mid")
  155. if midValue != nil {
  156. mid = midValue.(int64)
  157. }
  158. c.JSON(srv.CommentSubCursor(c, mid, arg, device))
  159. }