creator.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package http
  2. import (
  3. "io/ioutil"
  4. "net/http"
  5. "encoding/json"
  6. "go-common/app/interface/main/videoup/model/archive"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. func creatorEdit(c *bm.Context) {
  12. var (
  13. aid int64
  14. ap = &archive.ArcParam{}
  15. cp = &archive.CreatorParam{}
  16. err error
  17. )
  18. defer func() {
  19. //特例 creatorEdit
  20. ap.Title = cp.Title
  21. ap.Aid = cp.Aid
  22. ap.Tag = cp.Tag
  23. ap.Desc = cp.Desc
  24. ap.OpenElec = cp.OpenElec
  25. build, buvid := getBuildInfo(c)
  26. vdpSvc.SendArchiveLog(aid, build, buvid, "edit", "creator", ap, err)
  27. }()
  28. midI, _ := c.Get("mid")
  29. mid, _ := midI.(int64)
  30. if err = c.Bind(cp); err != nil {
  31. err = ecode.VideoupParamErr
  32. return
  33. }
  34. if cp.Aid == 0 {
  35. err = ecode.VideoupParamErr
  36. return
  37. }
  38. aid = cp.Aid
  39. ap.Aid = cp.Aid
  40. ap.Title = cp.Title
  41. ap.Desc = cp.Desc
  42. ap.Tag = cp.Tag
  43. ap.OpenElec = cp.OpenElec
  44. err = vdpSvc.CreatorEdit(c, mid, cp)
  45. if err != nil {
  46. c.JSON(nil, err)
  47. log.Error("addErr err(%+v)|cp(%+v)", err, cp)
  48. return
  49. }
  50. c.JSON(map[string]interface{}{
  51. "aid": cp.Aid,
  52. }, nil)
  53. }
  54. func creatorAdd(c *bm.Context) {
  55. var (
  56. aid int64
  57. ap = &archive.ArcParam{}
  58. cp = &archive.ArcParam{}
  59. err error
  60. )
  61. midI, _ := c.Get("mid")
  62. mid, ok := midI.(int64)
  63. if !ok || mid <= 0 {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. bs, err := ioutil.ReadAll(c.Request.Body)
  68. if err != nil {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. c.Request.Body.Close()
  73. err = json.Unmarshal(bs, ap)
  74. err = json.Unmarshal(bs, cp)
  75. if err != nil {
  76. c.JSON(nil, ecode.VideoupParamErr)
  77. return
  78. }
  79. ap.Mid = mid
  80. ap.UpFrom = archive.UpFromCreator
  81. defer func() {
  82. cp.IPv6 = ap.IPv6
  83. cp.Aid = ap.Aid
  84. cp.UpFrom = ap.UpFrom
  85. cp.Mid = ap.Mid
  86. build, buvid := getBuildInfo(c)
  87. vdpSvc.SendArchiveLog(aid, build, buvid, "add", "creator", cp, err)
  88. }()
  89. if err == nil {
  90. aid, err = vdpSvc.CreatorAdd(c, mid, ap)
  91. }
  92. if err != nil {
  93. c.JSON(nil, err)
  94. log.Error("addErr err(%+v)|ap(%+v)", err, ap)
  95. return
  96. }
  97. c.JSON(map[string]interface{}{
  98. "aid": aid,
  99. }, nil)
  100. }
  101. func creatorUpCover(c *bm.Context) {
  102. midI, _ := c.Get("mid")
  103. mid, ok := midI.(int64)
  104. if !ok || mid <= 0 {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. file, _, err := c.Request.FormFile("file")
  109. if err != nil {
  110. log.Error("c.Request().FormFile(\"file\") error(%v) | ", err)
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. bs, err := ioutil.ReadAll(file)
  115. file.Close()
  116. if err != nil {
  117. log.Error("ioutil.ReadAll(c.Request().Body) error(%v)", err)
  118. c.JSON(nil, ecode.RequestErr)
  119. return
  120. }
  121. ftype := http.DetectContentType(bs)
  122. if ftype != "image/jpeg" && ftype != "image/png" && ftype != "image/webp" {
  123. log.Error("filetype not allow file type(%s)", ftype)
  124. c.JSON(nil, ecode.RequestErr)
  125. return
  126. }
  127. url, err := vdpSvc.CreatorUpCover(c, ftype, bs, mid)
  128. if err != nil {
  129. c.JSON(nil, err)
  130. return
  131. }
  132. c.JSON(map[string]interface{}{
  133. "url": url,
  134. }, nil)
  135. }