app_danmu.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/metadata"
  8. "go-common/library/xstr"
  9. )
  10. func appDmList(c *bm.Context) {
  11. params := c.Request.Form
  12. pnStr := params.Get("pn")
  13. psStr := params.Get("ps")
  14. idStr := params.Get("id")
  15. pool := params.Get("pool")
  16. aidStr := params.Get("aid")
  17. midIStr := params.Get("mid")
  18. midStr, _ := c.Get("mid")
  19. mid := midStr.(int64)
  20. if mid <= 0 {
  21. c.JSON(nil, ecode.CreativeNotLogin)
  22. return
  23. }
  24. id, err := strconv.ParseInt(idStr, 10, 64)
  25. if err != nil || id <= 0 {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. aid, err := strconv.ParseInt(aidStr, 10, 64)
  30. if err != nil || aid <= 0 {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. pn, err := strconv.Atoi(pnStr)
  35. if err != nil || pn <= 0 {
  36. pn = 1
  37. }
  38. ps, err := strconv.Atoi(psStr)
  39. if err != nil || ps <= 0 || pn > 10 {
  40. ps = 10
  41. }
  42. ip := metadata.String(c, metadata.RemoteIP)
  43. order := "progress"
  44. orderStr := params.Get("order")
  45. if orderStr != order {
  46. order = "ctime"
  47. }
  48. list, err := danmuSvc.List(c, mid, aid, id, pn, ps, order, pool, midIStr, ip)
  49. if err != nil {
  50. c.JSON(nil, err)
  51. return
  52. }
  53. c.JSON(list, nil)
  54. }
  55. func appDmEdit(c *bm.Context) {
  56. params := c.Request.Form
  57. idStr := params.Get("cid")
  58. dmidsStr := params.Get("dmids")
  59. stateStr := params.Get("state")
  60. midStr, _ := c.Get("mid")
  61. mid := midStr.(int64)
  62. if mid <= 0 {
  63. c.JSON(nil, ecode.CreativeNotLogin)
  64. return
  65. }
  66. id, err := strconv.ParseInt(idStr, 10, 64)
  67. if err != nil || id <= 0 {
  68. err = ecode.RequestErr
  69. return
  70. }
  71. state, err := strconv.Atoi(stateStr)
  72. if err != nil {
  73. err = ecode.RequestErr
  74. return
  75. }
  76. var dmids []int64
  77. if dmids, err = xstr.SplitInts(dmidsStr); err != nil {
  78. c.JSON(nil, ecode.RequestErr)
  79. log.Error("xstr.SplitInts(dmidsStr %v) err(%v)", dmidsStr, err)
  80. return
  81. }
  82. for _, dmid := range dmids {
  83. if dmid <= 0 {
  84. c.JSON(nil, ecode.RequestErr)
  85. log.Error("dmids range err (dmid %d) err(%v)", dmid, err)
  86. return
  87. }
  88. }
  89. ip := metadata.String(c, metadata.RemoteIP)
  90. err = danmuSvc.Edit(c, mid, id, int8(state), dmids, ip)
  91. if err != nil {
  92. c.JSON(nil, err)
  93. }
  94. c.JSON(nil, nil)
  95. }
  96. func appDmRecent(c *bm.Context) {
  97. params := c.Request.Form
  98. pnStr := params.Get("pn")
  99. psStr := params.Get("ps")
  100. midStr, _ := c.Get("mid")
  101. mid := midStr.(int64)
  102. if mid <= 0 {
  103. c.JSON(nil, ecode.CreativeNotLogin)
  104. return
  105. }
  106. ip := metadata.String(c, metadata.RemoteIP)
  107. var (
  108. pn, ps int64
  109. err error
  110. )
  111. if pn, err = strconv.ParseInt(pnStr, 10, 64); err != nil || pn < 1 {
  112. pn = 1
  113. }
  114. if ps, err = strconv.ParseInt(psStr, 10, 64); err != nil || ps > 10 || ps < 1 {
  115. ps = 10
  116. }
  117. recent, err := danmuSvc.Recent(c, mid, pn, ps, ip)
  118. if err != nil {
  119. c.JSON(nil, err)
  120. return
  121. }
  122. c.JSON(recent, nil)
  123. }
  124. func appDmEditBatch(c *bm.Context) {
  125. params := c.Request.Form
  126. paramsStr := params.Get("params")
  127. midStr, _ := c.Get("mid")
  128. mid := midStr.(int64)
  129. if mid <= 0 {
  130. c.JSON(nil, ecode.CreativeNotLogin)
  131. return
  132. }
  133. ip := metadata.String(c, metadata.RemoteIP)
  134. err := danmuSvc.EditBatch(c, mid, paramsStr, ip)
  135. if err != nil {
  136. c.JSON(nil, err)
  137. }
  138. c.JSON(nil, nil)
  139. }