video.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/playlist/conf"
  5. "go-common/app/interface/main/playlist/model"
  6. favmdl "go-common/app/service/main/favorite/model"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. func videoList(c *bm.Context) {
  12. var (
  13. pid int64
  14. pn, ps int
  15. err error
  16. list *model.ArcList
  17. )
  18. params := c.Request.Form
  19. pidStr := params.Get("pid")
  20. pnStr := params.Get("pn")
  21. psStr := params.Get("ps")
  22. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  23. c.JSON(nil, ecode.RequestErr)
  24. return
  25. }
  26. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  27. pn = 1
  28. }
  29. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxPlArcsPs {
  30. ps = conf.Conf.Rule.MaxPlArcsPs
  31. }
  32. if list, err = plSvc.Videos(c, pid, pn, ps); err != nil {
  33. c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
  34. return
  35. }
  36. c.JSON(list, nil)
  37. }
  38. func toView(c *bm.Context) {
  39. var (
  40. pid, mid int64
  41. err error
  42. list *model.ToView
  43. )
  44. params := c.Request.Form
  45. if midStr, ok := c.Get("mid"); ok {
  46. mid = midStr.(int64)
  47. }
  48. pidStr := params.Get("pid")
  49. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  50. c.JSON(nil, ecode.RequestErr)
  51. return
  52. }
  53. if list, err = plSvc.ToView(c, mid, pid); err != nil {
  54. c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
  55. return
  56. }
  57. c.JSON(list, nil)
  58. }
  59. func check(c *bm.Context) {
  60. var (
  61. err error
  62. mid, pid int64
  63. aids []int64
  64. videos model.Videos
  65. )
  66. params := c.Request.Form
  67. midStr, _ := c.Get("mid")
  68. mid = midStr.(int64)
  69. aidStr := params.Get("aids")
  70. if aidStr == "" {
  71. c.JSON(nil, ecode.RequestErr)
  72. return
  73. }
  74. if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. aidMap := make(map[int64]int64, len(aids))
  79. for _, aid := range aids {
  80. aidMap[aid] = aid
  81. }
  82. if len(aidMap) < len(aids) {
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. pidStr := params.Get("pid")
  87. if pidStr != "" {
  88. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
  89. c.JSON(nil, ecode.RequestErr)
  90. return
  91. }
  92. }
  93. if videos, err = plSvc.CheckVideo(c, mid, pid, aids); err != nil {
  94. c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
  95. return
  96. }
  97. c.JSON(videos, nil)
  98. }
  99. func addVideo(c *bm.Context) {
  100. var (
  101. err error
  102. mid, pid int64
  103. aids []int64
  104. videos model.Videos
  105. )
  106. params := c.Request.Form
  107. midStr, _ := c.Get("mid")
  108. mid = midStr.(int64)
  109. aidStr := params.Get("aids")
  110. if aidStr == "" {
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
  115. c.JSON(nil, ecode.RequestErr)
  116. return
  117. }
  118. aidMap := make(map[int64]int64, len(aids))
  119. for _, aid := range aids {
  120. aidMap[aid] = aid
  121. }
  122. if len(aidMap) < len(aids) {
  123. c.JSON(nil, ecode.RequestErr)
  124. return
  125. }
  126. pidStr := params.Get("pid")
  127. if pidStr != "" {
  128. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
  129. c.JSON(nil, ecode.RequestErr)
  130. return
  131. }
  132. }
  133. if videos, err = plSvc.AddVideo(c, mid, pid, aids); err != nil {
  134. c.JSON(nil, switchCode(err, favmdl.TypePlayVideo))
  135. return
  136. }
  137. c.JSON(videos, nil)
  138. }
  139. func delVideo(c *bm.Context) {
  140. var (
  141. err error
  142. mid, pid int64
  143. aids []int64
  144. )
  145. params := c.Request.Form
  146. midStr, _ := c.Get("mid")
  147. mid = midStr.(int64)
  148. aidStr := params.Get("aids")
  149. if aidStr == "" {
  150. c.JSON(nil, ecode.RequestErr)
  151. return
  152. }
  153. if aids, err = xstr.SplitInts(aidStr); err != nil || len(aids) == 0 || len(aids) > conf.Conf.Rule.MaxArcChangeLimit {
  154. c.JSON(nil, ecode.RequestErr)
  155. return
  156. }
  157. aidMap := make(map[int64]int64, len(aids))
  158. for _, aid := range aids {
  159. aidMap[aid] = aid
  160. }
  161. if len(aidMap) < len(aids) {
  162. c.JSON(nil, ecode.RequestErr)
  163. return
  164. }
  165. pidStr := params.Get("pid")
  166. if pidStr != "" {
  167. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid < 0 {
  168. c.JSON(nil, ecode.RequestErr)
  169. return
  170. }
  171. }
  172. c.JSON(nil, switchCode(plSvc.DelVideo(c, mid, pid, aids), favmdl.TypePlayVideo))
  173. }
  174. func sortVideo(c *bm.Context) {
  175. var (
  176. mid, pid, aid, sort int64
  177. err error
  178. )
  179. params := c.Request.Form
  180. midStr, _ := c.Get("mid")
  181. mid = midStr.(int64)
  182. aidStr := params.Get("aid")
  183. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  184. c.JSON(nil, ecode.RequestErr)
  185. return
  186. }
  187. pidStr := params.Get("pid")
  188. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  189. c.JSON(nil, ecode.RequestErr)
  190. return
  191. }
  192. sortStr := params.Get("sort")
  193. if sort, err = strconv.ParseInt(sortStr, 10, 64); err != nil || sort <= 0 || sort > int64(conf.Conf.Rule.MaxVideoCnt) {
  194. c.JSON(nil, ecode.RequestErr)
  195. return
  196. }
  197. c.JSON(nil, switchCode(plSvc.SortVideo(c, mid, pid, aid, sort), favmdl.TypePlayVideo))
  198. }
  199. func editVideoDesc(c *bm.Context) {
  200. var (
  201. err error
  202. mid, pid, aid int64
  203. )
  204. params := c.Request.Form
  205. midStr, _ := c.Get("mid")
  206. mid = midStr.(int64)
  207. pidStr := params.Get("pid")
  208. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  209. c.JSON(nil, ecode.RequestErr)
  210. return
  211. }
  212. aidStr := params.Get("aid")
  213. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  214. c.JSON(nil, ecode.RequestErr)
  215. return
  216. }
  217. desc := params.Get("desc")
  218. if len([]rune(desc)) > conf.Conf.Rule.MaxVideoDescLimit {
  219. c.JSON(nil, ecode.RequestErr)
  220. return
  221. }
  222. c.JSON(nil, plSvc.EditVideoDesc(c, mid, pid, aid, desc))
  223. }
  224. func searchVideo(c *bm.Context) {
  225. var (
  226. err error
  227. pn, ps, count int
  228. list []*model.SearchArc
  229. )
  230. params := c.Request.Form
  231. pnStr := params.Get("pn")
  232. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  233. pn = 1
  234. }
  235. psStr := params.Get("ps")
  236. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxSearchArcPs {
  237. ps = conf.Conf.Rule.MaxSearchArcPs
  238. }
  239. query := params.Get("keyword")
  240. if query == "" || len([]rune(query)) > conf.Conf.Rule.MaxSearchLimit {
  241. c.JSON(nil, ecode.RequestErr)
  242. return
  243. }
  244. if list, count, err = plSvc.SearchVideos(c, pn, ps, query); err != nil {
  245. c.JSON(nil, ecode.RequestErr)
  246. return
  247. }
  248. data := make(map[string]interface{}, 2)
  249. page := map[string]int{
  250. "num": pn,
  251. "size": ps,
  252. "count": count,
  253. }
  254. data["page"] = page
  255. data["list"] = list
  256. c.JSON(data, nil)
  257. }