cm.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. xtime "go-common/library/time"
  10. )
  11. // upArchiveArr update archive attribute.
  12. func upCMArr(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. AdminID int64 `json:"admin_id"`
  26. RankAttr struct {
  27. Main int32 `json:"main"`
  28. RecentArc int32 `json:"recent_arc"`
  29. AllArc int32 `json:"all_arc"`
  30. } `json:"rank_attr"`
  31. DynamicAttr struct {
  32. Main int32 `json:"main"`
  33. } `json:"dynamic_attr"`
  34. RecommendAttr struct {
  35. Main int32 `json:"main"`
  36. } `json:"recommend_attr"`
  37. }
  38. if err = json.Unmarshal(bs, &ap); err != nil {
  39. log.Error("http upArchiveArr() json.Unmarshal(%s) error(%v)", string(bs), err)
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. if ap.Aid == 0 {
  44. log.Error("aid==0")
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. attrs := make(map[uint]int32, 6)
  49. attrs[archive.AttrBitNoRank] = ap.RankAttr.Main
  50. attrs[archive.AttrBitNoDynamic] = ap.DynamicAttr.Main
  51. attrs[archive.AttrBitNoRecommend] = ap.RecommendAttr.Main
  52. // forbid
  53. forbidAttrs := make(map[string]map[uint]int32, 3)
  54. forbidAttrs[archive.ForbidRank] = map[uint]int32{
  55. archive.ForbidRankMain: ap.RankAttr.Main,
  56. archive.ForbidRankRecentArc: ap.RankAttr.RecentArc,
  57. archive.ForbidRankAllArc: ap.RankAttr.AllArc,
  58. }
  59. forbidAttrs[archive.ForbidDynamic] = map[uint]int32{
  60. archive.ForbidDynamicMain: ap.DynamicAttr.Main,
  61. }
  62. forbidAttrs[archive.ForbidRecommend] = map[uint]int32{
  63. archive.ForbidRecommendMain: ap.RecommendAttr.Main,
  64. }
  65. // update attrs and forbid
  66. c.JSON(nil, vdaSvc.UpArchiveAttr(c, ap.Aid, ap.AdminID, attrs, forbidAttrs, ""))
  67. }
  68. // upCMArrDelay up cm archive delaytime
  69. func upCMArcDelay(c *bm.Context) {
  70. req := c.Request
  71. // read
  72. bs, err := ioutil.ReadAll(req.Body)
  73. if err != nil {
  74. log.Error("ioutil.ReadAll() error(%v)", err)
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. req.Body.Close()
  79. // params
  80. var ap struct {
  81. Aid int64 `json:"aid"`
  82. Dtime xtime.Time `json:"dtime"`
  83. }
  84. if err = json.Unmarshal(bs, &ap); err != nil {
  85. log.Error("http struct aid json.Unmarshal(%s) error(%v)", string(bs), err)
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. if ap.Aid == 0 {
  90. log.Error("aid==0")
  91. c.JSON(nil, ecode.RequestErr)
  92. return
  93. }
  94. if err = vdaSvc.UpArcDtime(c, ap.Aid, ap.Dtime); err != nil {
  95. log.Error("vdaSvc.UpArcDtime() error(%v)", err)
  96. c.JSON(nil, err)
  97. return
  98. }
  99. c.JSON(nil, nil)
  100. }