video.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package http
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // videoAudit up firstRound info.
  11. func videoAudit(c *bm.Context) {
  12. req := c.Request
  13. // read
  14. bs, err := ioutil.ReadAll(req.Body)
  15. if err != nil {
  16. log.Error("ioutil.ReadAll() error(%v)", err)
  17. c.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. req.Body.Close()
  21. // params
  22. var vp = &archive.VideoParam{}
  23. if err = json.Unmarshal(bs, &vp); err != nil {
  24. log.Error("http firstRound() json.Unmarshal(%s) error(%v)", string(bs), err)
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. // TODO check data.
  29. if vp.ID == 0 {
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. attrs := make(map[uint]int32, 6)
  34. attrs[archive.AttrBitNoRank] = vp.Attrs.NoRank
  35. attrs[archive.AttrBitNoDynamic] = vp.Attrs.NoDynamic
  36. attrs[archive.AttrBitNoSearch] = vp.Attrs.NoSearch
  37. attrs[archive.AttrBitNoRecommend] = vp.Attrs.NoRecommend
  38. attrs[archive.AttrBitOverseaLock] = vp.Attrs.OverseaLock
  39. attrs[archive.AttrBitPushBlog] = vp.Attrs.PushBlog
  40. if vp.TagID > 0 && vp.Status >= 0 {
  41. attrs[archive.AttrBitParentMode] = 1
  42. }
  43. c.JSON(nil, vdaSvc.VideoAudit(c, vp, attrs))
  44. }
  45. func batchVideo(c *bm.Context) {
  46. req := c.Request
  47. // read
  48. bs, err := ioutil.ReadAll(req.Body)
  49. if err != nil {
  50. log.Error("ioutil.ReadAll() error(%v)", err)
  51. c.JSON(nil, ecode.RequestErr)
  52. return
  53. }
  54. req.Body.Close()
  55. // params
  56. var vps = []*archive.VideoParam{}
  57. if err = json.Unmarshal(bs, &vps); err != nil {
  58. log.Error("http firstRound() json.Unmarshal(%s) error(%v)", string(bs), err)
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. if len(vps) == 0 {
  63. c.JSON(nil, ecode.RequestErr)
  64. return
  65. }
  66. if ok := vdaSvc.CheckVideo(vps); !ok {
  67. c.JSON(nil, ecode.RequestErr)
  68. return
  69. }
  70. c.JSON(nil, vdaSvc.BatchVideo(c, vps, archive.ActionVideoSubmit))
  71. }
  72. func upVideo(c *bm.Context) {
  73. req := c.Request
  74. // read
  75. bs, err := ioutil.ReadAll(req.Body)
  76. if err != nil {
  77. log.Error("ioutil.ReadAll() error(%v)", err)
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. req.Body.Close()
  82. // params
  83. var vp = &archive.VideoParam{}
  84. if err = json.Unmarshal(bs, &vp); err != nil {
  85. log.Error("http firstRound() json.Unmarshal(%s) error(%v)", string(bs), err)
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. // TODO check data.
  90. if vp.Aid == 0 {
  91. c.JSON(nil, ecode.RequestErr)
  92. return
  93. }
  94. c.JSON(nil, vdaSvc.UpVideo(c, vp))
  95. }
  96. func upWebLink(c *bm.Context) {
  97. req := c.Request
  98. // read
  99. bs, err := ioutil.ReadAll(req.Body)
  100. if err != nil {
  101. log.Error("ioutil.ReadAll() error(%v)", err)
  102. c.JSON(nil, ecode.RequestErr)
  103. return
  104. }
  105. req.Body.Close()
  106. // params
  107. var vp = &archive.VideoParam{}
  108. if err = json.Unmarshal(bs, &vp); err != nil {
  109. log.Error("http firstRound() json.Unmarshal(%s) error(%v)", string(bs), err)
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. // TODO check data.
  114. if vp.ID == 0 || vp.WebLink == "" {
  115. c.JSON(nil, ecode.RequestErr)
  116. return
  117. }
  118. c.JSON(nil, vdaSvc.UpWebLink(c, vp))
  119. }
  120. func delVideo(c *bm.Context) {
  121. req := c.Request
  122. // read
  123. bs, err := ioutil.ReadAll(req.Body)
  124. if err != nil {
  125. log.Error("ioutil.ReadAll() error(%v)", err)
  126. c.JSON(nil, ecode.RequestErr)
  127. return
  128. }
  129. req.Body.Close()
  130. // params
  131. var vp = &archive.VideoParam{}
  132. if err = json.Unmarshal(bs, &vp); err != nil {
  133. log.Error("http firstRound() json.Unmarshal(%s) error(%v)", string(bs), err)
  134. c.JSON(nil, ecode.RequestErr)
  135. return
  136. }
  137. // TODO check data.
  138. if vp.ID == 0 {
  139. c.JSON(nil, ecode.RequestErr)
  140. return
  141. }
  142. c.JSON(nil, vdaSvc.DelVideo(c, vp))
  143. }
  144. func changeIndex(c *bm.Context) {
  145. req := c.Request
  146. // read
  147. bs, err := ioutil.ReadAll(req.Body)
  148. if err != nil {
  149. log.Error("ioutil.ReadAll() error(%v)", err)
  150. c.JSON(nil, ecode.RequestErr)
  151. return
  152. }
  153. req.Body.Close()
  154. // params
  155. var lo = &archive.IndexParam{}
  156. if err = json.Unmarshal(bs, &lo); err != nil {
  157. log.Error("http changeIndex() json.Unmarshal(%s) error(%v)", string(bs), err)
  158. c.JSON(nil, ecode.RequestErr)
  159. return
  160. }
  161. if lo.Aid == 0 {
  162. log.Error("aid==%d", lo.Aid)
  163. c.JSON(nil, ecode.RequestErr)
  164. return
  165. }
  166. c.JSON(nil, vdaSvc.ChangeIndex(c, lo))
  167. }