pgc.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package http
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "go-common/app/service/main/videoup/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // addByPGC add archive info by PGC.
  11. func addByPGC(c *bm.Context) {
  12. req := c.Request
  13. bs, err := ioutil.ReadAll(req.Body)
  14. if err != nil {
  15. log.Error("ioutil.ReadAll() error(%v)", err)
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. req.Body.Close()
  20. // params
  21. var ap = &archive.ArcParam{}
  22. if err = json.Unmarshal(bs, ap); err != nil {
  23. log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
  28. log.Error("addByPGC func param is empty (%v)", ap)
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  33. log.Error("typeId (%d) not exist", ap.TypeID)
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. if ok := archive.InCopyrights(ap.Copyright); !ok {
  38. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. ap.UpFrom = archive.UpFromPGC
  43. aid, err := vdpSvc.AddByPGC(c, ap)
  44. if err != nil {
  45. log.Error("vdpSvc.AddByPGC() error(%v)", err)
  46. c.JSON(nil, err)
  47. return
  48. }
  49. c.JSON(map[string]int64{
  50. "aid": aid,
  51. }, nil)
  52. }
  53. // saddByPGC add secret archive info by PGC.
  54. func saddByPGC(c *bm.Context) {
  55. req := c.Request
  56. bs, err := ioutil.ReadAll(req.Body)
  57. if err != nil {
  58. log.Error("ioutil.ReadAll() error(%v)", err)
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. req.Body.Close()
  63. // params
  64. var ap = &archive.ArcParam{}
  65. if err = json.Unmarshal(bs, ap); err != nil {
  66. log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
  67. c.JSON(nil, ecode.RequestErr)
  68. return
  69. }
  70. if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
  71. log.Error("addByPGC func param is empty (%v)", ap)
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  76. log.Error("typeId (%d) not exist", ap.TypeID)
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. if ok := archive.InCopyrights(ap.Copyright); !ok {
  81. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. ap.UpFrom = archive.UpFromSecretPGC
  86. aid, err := vdpSvc.AddByPGC(c, ap)
  87. if err != nil {
  88. log.Error("vdpSvc.AddByPGC() error(%v)", err)
  89. c.JSON(nil, err)
  90. return
  91. }
  92. c.JSON(map[string]int64{
  93. "aid": aid,
  94. }, nil)
  95. }
  96. // editByPGC edit archive info by PGC.
  97. func editByPGC(c *bm.Context) {
  98. req := c.Request
  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 ap = &archive.ArcParam{}
  108. if err = json.Unmarshal(bs, ap); err != nil {
  109. log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
  114. log.Error("editByPGC func param is empty (%v)", ap)
  115. c.JSON(nil, ecode.RequestErr)
  116. return
  117. }
  118. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  119. log.Error("typeId (%d) not exist", ap.TypeID)
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. if ok := archive.InCopyrights(ap.Copyright); !ok {
  124. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  125. c.JSON(nil, ecode.RequestErr)
  126. return
  127. }
  128. ap.UpFrom = archive.UpFromPGC
  129. c.JSON(nil, vdpSvc.EditByPGC(c, ap))
  130. }
  131. // caddByPGC add coopera archive info by PGC.
  132. func caddByPGC(c *bm.Context) {
  133. req := c.Request
  134. bs, err := ioutil.ReadAll(req.Body)
  135. if err != nil {
  136. log.Error("ioutil.ReadAll() error(%v)", err)
  137. c.JSON(nil, ecode.RequestErr)
  138. return
  139. }
  140. req.Body.Close()
  141. // params
  142. var ap = &archive.ArcParam{}
  143. if err = json.Unmarshal(bs, ap); err != nil {
  144. log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
  149. log.Error("addByPGC func param is empty (%v)", ap)
  150. c.JSON(nil, ecode.RequestErr)
  151. return
  152. }
  153. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  154. log.Error("typeId (%d) not exist", ap.TypeID)
  155. c.JSON(nil, ecode.RequestErr)
  156. return
  157. }
  158. if ok := archive.InCopyrights(ap.Copyright); !ok {
  159. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  160. c.JSON(nil, ecode.RequestErr)
  161. return
  162. }
  163. ap.UpFrom = archive.UpFromCoopera
  164. aid, err := vdpSvc.AddByPGC(c, ap)
  165. if err != nil {
  166. log.Error("vdpSvc.AddByPGC() error(%v)", err)
  167. c.JSON(nil, err)
  168. return
  169. }
  170. c.JSON(map[string]int64{
  171. "aid": aid,
  172. }, nil)
  173. }
  174. // ceditByPGC edit coopera archive info by PGC.
  175. func ceditByPGC(c *bm.Context) {
  176. req := c.Request
  177. bs, err := ioutil.ReadAll(req.Body)
  178. if err != nil {
  179. log.Error("ioutil.ReadAll() error(%v)", err)
  180. c.JSON(nil, ecode.RequestErr)
  181. return
  182. }
  183. req.Body.Close()
  184. // params
  185. var ap = &archive.ArcParam{}
  186. if err = json.Unmarshal(bs, ap); err != nil {
  187. log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
  188. c.JSON(nil, ecode.RequestErr)
  189. return
  190. }
  191. if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
  192. log.Error("editByPGC func param is empty (%v)", ap)
  193. c.JSON(nil, ecode.RequestErr)
  194. return
  195. }
  196. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  197. log.Error("typeId (%d) not exist", ap.TypeID)
  198. c.JSON(nil, ecode.RequestErr)
  199. return
  200. }
  201. if ok := archive.InCopyrights(ap.Copyright); !ok {
  202. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  203. c.JSON(nil, ecode.RequestErr)
  204. return
  205. }
  206. ap.UpFrom = archive.UpFromCoopera
  207. c.JSON(nil, vdpSvc.EditByPGC(c, ap))
  208. }