web.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package http
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "io/ioutil"
  6. "net/http"
  7. "strings"
  8. "go-common/app/interface/main/videoup/model/archive"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. bm "go-common/library/net/http/blademaster"
  12. )
  13. func webAdd(c *bm.Context) {
  14. var (
  15. aid int64
  16. ap = &archive.ArcParam{}
  17. cp = &archive.ArcParam{}
  18. err error
  19. )
  20. midI, _ := c.Get("mid")
  21. mid, ok := midI.(int64)
  22. if !ok || mid <= 0 {
  23. c.JSON(nil, ecode.CreativeNotLogin)
  24. return
  25. }
  26. bs, err := ioutil.ReadAll(c.Request.Body)
  27. if err != nil {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. c.Request.Body.Close()
  32. err = json.Unmarshal(bs, ap)
  33. err = json.Unmarshal(bs, cp)
  34. if err != nil {
  35. c.JSON(nil, ecode.VideoupParamErr)
  36. return
  37. }
  38. ap.Aid = 0
  39. ap.Mid = mid
  40. ap.UpFrom = archive.UpFromWeb
  41. // code, msg, data := vdpSvc.WebFilterArcParam(c, ap, ip)
  42. // if code != 0 {
  43. // c.Error = ecode.VideoupFieldFilterForbid
  44. // c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  45. // "code": code,
  46. // "message": msg,
  47. // "data": data,
  48. // }))
  49. // return
  50. // }
  51. defer func() {
  52. cp.Aid = ap.Aid
  53. cp.Mid = ap.Mid
  54. cp.IPv6 = ap.IPv6
  55. cp.UpFrom = ap.UpFrom
  56. build, buvid := getBuildInfo(c)
  57. vdpSvc.SendArchiveLog(aid, build, buvid, "add", "web", cp, err)
  58. }()
  59. aid, err = vdpSvc.WebAdd(c, mid, ap, false)
  60. if err != nil {
  61. log.Error("vdpSvc.WebAdd Err mid(%+d)|ap(%+v)|err(%+v)", mid, ap, err)
  62. c.JSON(nil, err)
  63. return
  64. }
  65. c.JSON(map[string]interface{}{
  66. "aid": aid,
  67. }, nil)
  68. }
  69. func webEdit(c *bm.Context) {
  70. var (
  71. aid int64
  72. ap = &archive.ArcParam{}
  73. cp = &archive.ArcParam{}
  74. err error
  75. )
  76. midI, _ := c.Get("mid")
  77. mid, ok := midI.(int64)
  78. if !ok || mid <= 0 {
  79. c.JSON(nil, ecode.CreativeNotLogin)
  80. return
  81. }
  82. bs, err := ioutil.ReadAll(c.Request.Body)
  83. if err != nil {
  84. c.JSON(nil, ecode.RequestErr)
  85. return
  86. }
  87. c.Request.Body.Close()
  88. err = json.Unmarshal(bs, ap)
  89. err = json.Unmarshal(bs, cp)
  90. if err != nil {
  91. c.JSON(nil, ecode.VideoupParamErr)
  92. return
  93. }
  94. aid = ap.Aid
  95. ap.Mid = mid
  96. ap.UpFrom = archive.UpFromWeb
  97. // code, msg, data := vdpSvc.WebFilterArcParam(c, ap, ip)
  98. // if code != 0 {
  99. // c.Error = ecode.VideoupFieldFilterForbid
  100. // c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  101. // "code": code,
  102. // "message": msg,
  103. // "data": data,
  104. // }))
  105. // return
  106. // }
  107. defer func() {
  108. cp.Aid = ap.Aid
  109. cp.Mid = ap.Mid
  110. cp.UpFrom = ap.UpFrom
  111. cp.IPv6 = ap.IPv6
  112. build, buvid := getBuildInfo(c)
  113. vdpSvc.SendArchiveLog(aid, build, buvid, "edit", "web", cp, err)
  114. }()
  115. err = vdpSvc.WebEdit(c, ap, mid)
  116. if err != nil {
  117. log.Error("vdpSvc.WebEdit Err mid(%+d)|ap(%+v)|err(%+v)", mid, ap, err)
  118. c.JSON(nil, err)
  119. return
  120. }
  121. c.JSON(map[string]interface{}{
  122. "aid": ap.Aid,
  123. }, nil)
  124. }
  125. func webUpCover(c *bm.Context) {
  126. midI, _ := c.Get("mid")
  127. mid, ok := midI.(int64)
  128. if !ok || mid <= 0 {
  129. c.JSON(nil, ecode.CreativeNotLogin)
  130. return
  131. }
  132. cover := c.Request.Form.Get("cover")
  133. c.Request.Form.Del("cover")
  134. ss := strings.Split(cover, ",")
  135. if len(ss) != 2 || len(ss[1]) == 0 {
  136. log.Error("cover(%s) format error", cover)
  137. c.JSON(nil, ecode.RequestErr)
  138. return
  139. }
  140. bs, err := base64.StdEncoding.DecodeString(ss[1])
  141. if err != nil {
  142. log.Error("base64.StdEncoding.DecodeString(%s) error(%v)", ss[1], err)
  143. c.JSON(nil, ecode.RequestErr)
  144. return
  145. }
  146. ftype := http.DetectContentType(bs)
  147. if ftype != "image/jpeg" && ftype != "image/png" && ftype != "image/webp" {
  148. log.Error("file type not allow file type(%s)", ftype)
  149. c.JSON(nil, ecode.RequestErr)
  150. return
  151. }
  152. url, err := vdpSvc.WebUpCover(c, ftype, bs, mid)
  153. if err != nil {
  154. c.JSON(nil, err)
  155. return
  156. }
  157. c.JSON(map[string]interface{}{
  158. "url": url,
  159. }, nil)
  160. }
  161. func webFilter(c *bm.Context) {
  162. midI, _ := c.Get("mid")
  163. mid, ok := midI.(int64)
  164. if !ok || mid <= 0 {
  165. c.JSON(nil, ecode.CreativeNotLogin)
  166. return
  167. }
  168. var (
  169. err error
  170. )
  171. // msg := c.Request.Form.Get("msg")
  172. // if len(msg) != 0 {
  173. // _, err = vdpSvc.WebSingleFilter(c, msg)
  174. // }
  175. c.JSON(nil, err)
  176. }
  177. // staffTitleFilter 过滤联合投稿职能
  178. func webStaffTitleFilter(c *bm.Context) {
  179. midI, _ := c.Get("mid")
  180. mid, ok := midI.(int64)
  181. if !ok || mid <= 0 {
  182. c.JSON(nil, ecode.CreativeNotLogin)
  183. return
  184. }
  185. var (
  186. err error
  187. )
  188. title := c.Request.Form.Get("title")
  189. if len(title) != 0 {
  190. var hit []string
  191. _, hit, err = vdpSvc.WebSingleFilter(c, title)
  192. if len(hit) > 0 {
  193. err = ecode.VideoupStaffTitleFilter
  194. }
  195. }
  196. c.JSON(nil, err)
  197. }
  198. func webCmAdd(c *bm.Context) {
  199. var (
  200. aid int64
  201. ap = &archive.ArcParam{}
  202. cp = &archive.ArcParam{}
  203. err error
  204. )
  205. midI, _ := c.Get("mid")
  206. mid, ok := midI.(int64)
  207. if !ok || mid <= 0 {
  208. c.JSON(nil, ecode.CreativeNotLogin)
  209. return
  210. }
  211. bs, err := ioutil.ReadAll(c.Request.Body)
  212. if err != nil {
  213. c.JSON(nil, ecode.RequestErr)
  214. return
  215. }
  216. c.Request.Body.Close()
  217. err = json.Unmarshal(bs, ap)
  218. err = json.Unmarshal(bs, cp)
  219. if err != nil {
  220. c.JSON(nil, ecode.VideoupParamErr)
  221. return
  222. }
  223. ap.Mid = mid
  224. ap.UpFrom = archive.UpFromCM
  225. defer func() {
  226. cp.Aid = ap.Aid
  227. cp.Mid = ap.Mid
  228. cp.IPv6 = ap.IPv6
  229. cp.UpFrom = ap.UpFrom
  230. build, buvid := getBuildInfo(c)
  231. vdpSvc.SendArchiveLog(aid, build, buvid, "add", "cm", cp, err)
  232. }()
  233. aid, err = vdpSvc.WebCmAdd(c, mid, ap)
  234. if err != nil {
  235. log.Error("vdpSvc.WebCmAdd Err mid(%+d)|ap(%+v)|err(%+v)", mid, ap, err)
  236. c.JSON(nil, err)
  237. return
  238. }
  239. c.JSON(map[string]interface{}{
  240. "aid": aid,
  241. }, nil)
  242. }