pgc.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package http
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "time"
  6. "go-common/app/admin/main/videoup/model/archive"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. // passByPGC update archive state pass by pgc
  12. func passByPGC(c *bm.Context) {
  13. req := c.Request
  14. // read
  15. bs, err := ioutil.ReadAll(req.Body)
  16. if err != nil {
  17. log.Error("ioutil.ReadAll() error(%v)", err)
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. req.Body.Close()
  22. // params
  23. var ap struct {
  24. Aid int64 `json:"aid"`
  25. Gid int64 `json:"gid"`
  26. IsJump int32 `json:"is_jump"`
  27. AllowBp int32 `json:"allow_bp"`
  28. IsBangumi int32 `json:"is_bangumi"`
  29. IsMovie int32 `json:"is_movie"`
  30. BadgePay int32 `json:"is_pay"`
  31. IsPGC int32 `json:"is_pgc"`
  32. RedirectURL string `json:"redirect_url"`
  33. }
  34. if err = json.Unmarshal(bs, &ap); err != nil {
  35. log.Error("http upArchiveArr() json.Unmarshal(%s) error(%v)", string(bs), err)
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. if ap.Aid == 0 {
  40. log.Error("aid==0")
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. attrs := make(map[uint]int32, 7)
  45. attrs[archive.AttrBitJumpURL] = ap.IsJump
  46. attrs[archive.AttrBitAllowBp] = ap.AllowBp
  47. attrs[archive.AttrBitIsBangumi] = ap.IsBangumi
  48. attrs[archive.AttrBitIsMovie] = ap.IsMovie
  49. attrs[archive.AttrBitBadgepay] = ap.BadgePay
  50. attrs[archive.AttrBitIsPGC] = ap.IsPGC
  51. attrs[archive.AttrBitLimitArea] = 0
  52. if ap.Gid > 1 {
  53. attrs[archive.AttrBitLimitArea] = 1
  54. }
  55. c.JSON(nil, vdaSvc.PassByPGC(c, ap.Aid, ap.Gid, attrs, ap.RedirectURL, time.Now()))
  56. }
  57. // modifyByPGC update archive attr by pgc
  58. func modifyByPGC(c *bm.Context) {
  59. req := c.Request
  60. // read
  61. bs, err := ioutil.ReadAll(req.Body)
  62. if err != nil {
  63. log.Error("ioutil.ReadAll() error(%v)", err)
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. req.Body.Close()
  68. // params
  69. var ap struct {
  70. Aid int64 `json:"aid"`
  71. Gid int64 `json:"gid"`
  72. IsJump int32 `json:"is_jump"`
  73. AllowBp int32 `json:"allow_bp"`
  74. IsBangumi int32 `json:"is_bangumi"`
  75. IsMovie int32 `json:"is_movie"`
  76. BadgePay int32 `json:"is_pay"`
  77. IsPGC int32 `json:"is_pgc"`
  78. RedirectURL string `json:"redirect_url"`
  79. }
  80. if err = json.Unmarshal(bs, &ap); err != nil {
  81. log.Error("http modArchiveArr() json.Unmarshal(%s) error(%v)", string(bs), err)
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. if ap.Aid == 0 {
  86. log.Error("aid==0")
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. attrs := make(map[uint]int32, 7)
  91. attrs[archive.AttrBitJumpURL] = ap.IsJump
  92. attrs[archive.AttrBitAllowBp] = ap.AllowBp
  93. attrs[archive.AttrBitIsBangumi] = ap.IsBangumi
  94. attrs[archive.AttrBitIsMovie] = ap.IsMovie
  95. attrs[archive.AttrBitBadgepay] = ap.BadgePay
  96. attrs[archive.AttrBitIsPGC] = ap.IsPGC
  97. attrs[archive.AttrBitLimitArea] = 0
  98. if ap.Gid > 1 {
  99. attrs[archive.AttrBitLimitArea] = 1
  100. }
  101. c.JSON(nil, vdaSvc.ModifyByPGC(c, ap.Aid, ap.Gid, attrs, ap.RedirectURL))
  102. }
  103. // lockByPGC update archive state to lockbid by pgc
  104. func lockByPGC(c *bm.Context) {
  105. req := c.Request
  106. // read
  107. bs, err := ioutil.ReadAll(req.Body)
  108. if err != nil {
  109. log.Error("ioutil.ReadAll() error(%v)", err)
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. req.Body.Close()
  114. // params
  115. var ap struct {
  116. Aid int64 `json:"aid"`
  117. }
  118. if err = json.Unmarshal(bs, &ap); err != nil {
  119. log.Error("http struct aid json.Unmarshal(%s) error(%v)", string(bs), err)
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. if ap.Aid == 0 {
  124. log.Error("aid==0")
  125. c.JSON(nil, ecode.RequestErr)
  126. return
  127. }
  128. c.JSON(nil, vdaSvc.LockByPGC(c, ap.Aid))
  129. }