web_v2.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "go-common/app/interface/main/videoup/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func webV2Add(c *bm.Context) {
  11. var (
  12. aid int64
  13. ap = &archive.ArcParam{}
  14. cp = &archive.ArcParam{}
  15. err error
  16. validated bool
  17. )
  18. midI, _ := c.Get("mid")
  19. mid, ok := midI.(int64)
  20. if !ok || mid <= 0 {
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. bs, err := ioutil.ReadAll(c.Request.Body)
  25. if err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. c.Request.Body.Close()
  30. err = json.Unmarshal(bs, ap)
  31. err = json.Unmarshal(bs, cp)
  32. if err != nil {
  33. c.JSON(nil, ecode.VideoupParamErr)
  34. return
  35. }
  36. defer func() {
  37. cp.Aid = ap.Aid
  38. cp.Mid = ap.Mid
  39. cp.IPv6 = ap.IPv6
  40. cp.UpFrom = ap.UpFrom
  41. build, buvid := getBuildInfo(c)
  42. vdpSvc.SendArchiveLog(aid, build, buvid, "add", "web/v2", cp, err)
  43. }()
  44. validated, err = vdpSvc.Validate(c, ap.Geetest, "web", mid)
  45. if validated || err == ecode.CreativeGeetestAPIErr {
  46. ap.Mid = mid
  47. ap.UpFrom = archive.UpFromWeb
  48. aid, err = vdpSvc.WebAdd(c, mid, ap, validated)
  49. if err != nil {
  50. log.Error("vdpSvc.WebAdd Err mid(%+d)|ap(%+v)|err(%+v)", mid, ap, err)
  51. c.JSON(nil, err)
  52. return
  53. }
  54. c.JSON(map[string]interface{}{
  55. "aid": aid,
  56. }, nil)
  57. } else {
  58. c.JSON(nil, ecode.CreativeGeetestErr)
  59. }
  60. }