creator_danmu.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 creatorDmList(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. midIStr := params.Get("mid")
  17. midStr, _ := c.Get("mid")
  18. mid := midStr.(int64)
  19. if mid <= 0 {
  20. c.JSON(nil, ecode.CreativeNotLogin)
  21. return
  22. }
  23. aidStr := params.Get("aid")
  24. aid, err := strconv.ParseInt(aidStr, 10, 64)
  25. if err != nil || aid <= 0 {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. id, err := strconv.ParseInt(idStr, 10, 64)
  30. if err != nil || id <= 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 {
  40. ps = 20
  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 creatorDmEdit(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. return
  94. }
  95. c.JSON(nil, nil)
  96. }
  97. func creatorDmRecent(c *bm.Context) {
  98. params := c.Request.Form
  99. pnStr := params.Get("pn")
  100. psStr := params.Get("ps")
  101. midStr, _ := c.Get("mid")
  102. mid := midStr.(int64)
  103. if mid <= 0 {
  104. c.JSON(nil, ecode.CreativeNotLogin)
  105. return
  106. }
  107. ip := metadata.String(c, metadata.RemoteIP)
  108. var (
  109. pn, ps int64
  110. err error
  111. )
  112. if pn, err = strconv.ParseInt(pnStr, 10, 64); err != nil || pn < 1 {
  113. pn = 1
  114. }
  115. if ps, err = strconv.ParseInt(psStr, 10, 64); err != nil || ps > 20 || ps < 1 {
  116. ps = 20
  117. }
  118. order := "playtime"
  119. orderStr := params.Get("order")
  120. if orderStr != order {
  121. order = "ctime"
  122. }
  123. recent, err := danmuSvc.Recent(c, mid, pn, ps, ip)
  124. if err != nil {
  125. c.JSON(nil, err)
  126. return
  127. }
  128. c.JSON(recent, nil)
  129. }
  130. func creatorDmEditBatch(c *bm.Context) {
  131. params := c.Request.Form
  132. paramsStr := params.Get("params")
  133. midStr, _ := c.Get("mid")
  134. mid := midStr.(int64)
  135. if mid <= 0 {
  136. c.JSON(nil, ecode.CreativeNotLogin)
  137. return
  138. }
  139. ip := metadata.String(c, metadata.RemoteIP)
  140. err := danmuSvc.EditBatch(c, mid, paramsStr, ip)
  141. if err != nil {
  142. c.JSON(nil, err)
  143. return
  144. }
  145. c.JSON(nil, nil)
  146. }