dm.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. func contentList(c *bm.Context) {
  11. var (
  12. v = new(model.SearchDMParams)
  13. )
  14. if err := c.Bind(v); err != nil {
  15. return
  16. }
  17. c.JSON(dmSvc.DMSearch(c, v))
  18. }
  19. // xmlCacheFlush flush danmu xml cache.
  20. func xmlCacheFlush(c *bm.Context) {
  21. var (
  22. err error
  23. tp = int64(model.SubTypeVideo)
  24. p = c.Request.Form
  25. )
  26. if p.Get("type") != "" {
  27. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. }
  32. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  33. if err != nil {
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. dmSvc.XMLCacheFlush(c, int32(tp), oid)
  38. c.JSON(nil, nil)
  39. }
  40. // dmSearch danmu content List by cid
  41. func dmSearch(c *bm.Context) {
  42. p := c.Request.Form
  43. params := &model.SearchDMParams{
  44. Mid: model.CondIntNil,
  45. State: p.Get("state"),
  46. Pool: p.Get("pool"),
  47. ProgressFrom: model.CondIntNil,
  48. ProgressTo: model.CondIntNil,
  49. CtimeFrom: model.CondIntNil,
  50. CtimeTo: model.CondIntNil,
  51. Page: 1,
  52. Size: 100,
  53. Sort: p.Get("sort"),
  54. Order: p.Get("order"),
  55. Keyword: p.Get("keyword"),
  56. IP: p.Get("ip"),
  57. Attrs: p.Get("attrs"),
  58. }
  59. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  60. if err != nil {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. params.Type = int32(tp)
  65. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  66. if err != nil {
  67. log.Error("param err oid %s %v", p.Get("oid"), err)
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. params.Oid = oid
  72. if p.Get("page") != "" {
  73. if params.Page, err = strconv.ParseInt(p.Get("page"), 10, 64); err != nil {
  74. log.Error("param err page %s %v", p.Get("page"), err)
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. }
  79. if p.Get("page_size") != "" {
  80. if params.Size, err = strconv.ParseInt(p.Get("page_size"), 10, 64); err != nil {
  81. log.Error("param err page_size %s %v", p.Get("page_size"), err)
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. }
  86. if p.Get("mid") != "" {
  87. if params.Mid, err = strconv.ParseInt(p.Get("mid"), 10, 64); err != nil {
  88. log.Error("param err mid %s %v", p.Get("mid"), err)
  89. c.JSON(nil, ecode.RequestErr)
  90. return
  91. }
  92. }
  93. if p.Get("progress_from") != "" {
  94. if params.ProgressFrom, err = strconv.ParseInt(p.Get("progress_from"), 10, 64); err != nil {
  95. log.Error("param err progress_from %s %v", p.Get("progress_from"), err)
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. }
  100. if p.Get("progress_to") != "" {
  101. if params.ProgressTo, err = strconv.ParseInt(p.Get("progress_to"), 10, 64); err != nil {
  102. log.Error("param err progress_to %s %v", p.Get("progress_to"), err)
  103. c.JSON(nil, ecode.RequestErr)
  104. return
  105. }
  106. }
  107. if p.Get("ctime_from") != "" {
  108. if params.CtimeFrom, err = strconv.ParseInt(p.Get("ctime_from"), 10, 64); err != nil {
  109. log.Error("param err ctime_from %s %v", p.Get("ctime_from"), err)
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. }
  114. if p.Get("ctime_to") != "" {
  115. if params.CtimeTo, err = strconv.ParseInt(p.Get("ctime_to"), 10, 64); err != nil {
  116. log.Error("param err ctime_to %s %v", p.Get("ctime_to"), err)
  117. c.JSON(nil, ecode.RequestErr)
  118. return
  119. }
  120. }
  121. data, err := dmSvc.DMSearch(c, params)
  122. c.JSON(data, err)
  123. }
  124. // editDMState batch operation by danmu content id
  125. func editDMState(c *bm.Context) {
  126. var (
  127. moral, reason int64
  128. p = c.Request.Form
  129. )
  130. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  131. if err != nil {
  132. c.JSON(nil, ecode.RequestErr)
  133. return
  134. }
  135. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  136. if err != nil {
  137. c.JSON(nil, ecode.RequestErr)
  138. return
  139. }
  140. if p.Get("reason_id") != "" {
  141. reason, err = strconv.ParseInt(p.Get("reason_id"), 10, 64)
  142. if err != nil {
  143. c.JSON(nil, ecode.RequestErr)
  144. return
  145. }
  146. }
  147. state, err := strconv.ParseInt(p.Get("state"), 10, 64)
  148. if err != nil {
  149. c.JSON(nil, ecode.RequestErr)
  150. return
  151. }
  152. if p.Get("moral") != "" {
  153. moral, err = strconv.ParseInt(p.Get("moral"), 10, 64)
  154. if err != nil {
  155. c.JSON(nil, ecode.RequestErr)
  156. return
  157. }
  158. }
  159. adminID, err := strconv.ParseInt(p.Get("adminId"), 10, 64)
  160. if err != nil || adminID <= 0 {
  161. c.JSON(nil, ecode.RequestErr)
  162. return
  163. }
  164. uname := p.Get("uname")
  165. if uname == "" {
  166. c.JSON(nil, ecode.RequestErr)
  167. log.Error("empty uname is not allow")
  168. return
  169. }
  170. remark := p.Get("remark")
  171. dmids, err := xstr.SplitInts(p.Get("dmids"))
  172. if err != nil || len(dmids) == 0 {
  173. c.JSON(nil, ecode.RequestErr)
  174. return
  175. }
  176. err = dmSvc.EditDMState(c, int32(tp), int32(state), oid, int8(reason), dmids, float64(moral), adminID, uname, remark)
  177. c.JSON(nil, err)
  178. }
  179. // editDMPool batch operation by danmu content id
  180. func editDMPool(c *bm.Context) {
  181. p := c.Request.Form
  182. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  183. if err != nil {
  184. c.JSON(nil, ecode.RequestErr)
  185. return
  186. }
  187. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  188. if err != nil {
  189. c.JSON(nil, ecode.RequestErr)
  190. return
  191. }
  192. pool, err := strconv.ParseInt(p.Get("pool"), 10, 64)
  193. if err != nil || (pool != 0 && pool != 1) {
  194. c.JSON(nil, ecode.RequestErr)
  195. return
  196. }
  197. dmids, err := xstr.SplitInts(p.Get("dmids"))
  198. if err != nil || len(dmids) == 0 {
  199. c.JSON(nil, ecode.RequestErr)
  200. return
  201. }
  202. adminID, err := strconv.ParseInt(p.Get("adminId"), 10, 64)
  203. if err != nil || adminID <= 0 {
  204. c.JSON(nil, ecode.RequestErr)
  205. return
  206. }
  207. err = dmSvc.EditDMPool(c, int32(tp), oid, int32(pool), dmids, adminID)
  208. c.JSON(nil, err)
  209. }
  210. // editDMAttr change attr
  211. func editDMAttr(c *bm.Context) {
  212. var (
  213. p = c.Request.Form
  214. bit uint
  215. value int32
  216. )
  217. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  218. if err != nil {
  219. c.JSON(nil, ecode.RequestErr)
  220. return
  221. }
  222. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  223. if err != nil {
  224. c.JSON(nil, ecode.RequestErr)
  225. return
  226. }
  227. attr, err := strconv.ParseInt(p.Get("attr"), 10, 64)
  228. if err != nil {
  229. c.JSON(nil, ecode.RequestErr)
  230. return
  231. }
  232. switch attr {
  233. case 0: // unprotect dm
  234. bit = model.AttrProtect
  235. value = model.AttrNo
  236. case 1: // protect dm
  237. bit = model.AttrProtect
  238. value = model.AttrYes
  239. default:
  240. c.JSON(nil, ecode.RequestErr)
  241. return
  242. }
  243. dmids, err := xstr.SplitInts(p.Get("dmids"))
  244. if err != nil || len(dmids) == 0 {
  245. c.JSON(nil, ecode.RequestErr)
  246. return
  247. }
  248. adminID, err := strconv.ParseInt(p.Get("adminId"), 10, 64)
  249. if err != nil || adminID <= 0 {
  250. c.JSON(nil, ecode.RequestErr)
  251. return
  252. }
  253. err = dmSvc.EditDMAttr(c, int32(tp), oid, dmids, bit, value, adminID)
  254. c.JSON(nil, err)
  255. }
  256. // dmIndexInfo get dm_index info
  257. func dmIndexInfo(c *bm.Context) {
  258. p := c.Request.Form
  259. cid, err := strconv.ParseInt(p.Get("cid"), 10, 64)
  260. if err != nil {
  261. c.JSON(nil, ecode.RequestErr)
  262. return
  263. }
  264. info, err := dmSvc.DMIndexInfo(c, cid)
  265. c.JSON(info, err)
  266. }
  267. func fixDMCount(c *bm.Context) {
  268. p := c.Request.Form
  269. aid, err := strconv.ParseInt(p.Get("aid"), 10, 64)
  270. if err != nil {
  271. c.JSON(nil, ecode.RequestErr)
  272. return
  273. }
  274. err = dmSvc.FixDMCount(c, aid)
  275. c.JSON(nil, err)
  276. }