ugc.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // addArchive add archive.
  11. func addArchive(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. var ap = &archive.ArcParam{}
  21. if err = json.Unmarshal(bs, ap); err != nil {
  22. log.Error("http addArchive() json.Unmarshal(%s) error(%v)", string(bs), err)
  23. c.JSON(nil, ecode.RequestErr)
  24. return
  25. }
  26. if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || len(ap.Videos) == 0 {
  27. log.Error("http addArchive() func param is empty (%d)|(%d)|(%d)|(%s)|(%s)|(%s)|(%v)", ap.Mid, ap.TypeID, ap.Copyright, ap.Title, ap.Tag, ap.Desc, ap.Videos)
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  32. log.Error("typeId (%d) not exist", ap.TypeID)
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. if ok := archive.InCopyrights(ap.Copyright); !ok {
  37. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. aid, err := vdpSvc.AddByUGC(c, ap)
  42. if err != nil {
  43. log.Error("vdpSvc.AddArchive() error(%v)", err)
  44. c.JSON(nil, err)
  45. return
  46. }
  47. c.JSON(map[string]int64{
  48. "aid": aid,
  49. }, nil)
  50. }
  51. // editArchive edit archive.
  52. func editArchive(c *bm.Context) {
  53. req := c.Request
  54. bs, err := ioutil.ReadAll(req.Body)
  55. if err != nil {
  56. log.Error("ioutil.ReadAll() error(%v)", err)
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. req.Body.Close()
  61. // params
  62. var ap = &archive.ArcParam{}
  63. if err = json.Unmarshal(bs, ap); err != nil {
  64. log.Error("http editArchive() json.Unmarshal(%s) error(%v)", string(bs), err)
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" {
  69. log.Error("http editArchive() func param is empty (%v)", ap)
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
  74. log.Error("typeId (%d) not exist", ap.TypeID)
  75. c.JSON(nil, ecode.RequestErr)
  76. return
  77. }
  78. if ok := archive.InCopyrights(ap.Copyright); !ok {
  79. log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. if err = vdpSvc.EditByUGC(c, ap); err != nil {
  84. log.Error("vdpSvc.EditByUGC() error(%v)", err)
  85. c.JSON(nil, err)
  86. return
  87. }
  88. c.JSON(nil, nil)
  89. }
  90. // editMissionByUGC edit archive mission by UGC.
  91. func editMissionByUGC(c *bm.Context) {
  92. v := &archive.ArcMissionParam{}
  93. if err := c.Bind(v); err != nil {
  94. return
  95. }
  96. c.JSON(nil, vdpSvc.EditMissionByUGC(c, v))
  97. }
  98. // queryDynamic edit archive mission by UGC.
  99. func queryDynamic(c *bm.Context) {
  100. v := &archive.ArcDynamicParam{}
  101. if err := c.Bind(v); err != nil {
  102. return
  103. }
  104. can, err := vdpSvc.QueryDynamicSetting(c, v)
  105. if err != nil {
  106. c.JSON(nil, err)
  107. return
  108. }
  109. var repostBanned = int8(0)
  110. if !can {
  111. repostBanned = 1
  112. }
  113. c.JSON(map[string]int8{
  114. "repost_banned": repostBanned,
  115. }, err)
  116. }