api.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package data
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "strings"
  7. "go-common/app/interface/main/creative/model/data"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _statURL = "/data/member/upinfo/%d.json"
  13. _tagv2URL = "/tag_predict/v2"
  14. _coverURL = "/cover_recomm"
  15. )
  16. // Stat get user stat play/fans/...
  17. func (d *Dao) stat(c context.Context, mid int64, ip string) (st *data.Stat, err error) {
  18. var res struct {
  19. Code int `json:"code"`
  20. *data.Stat
  21. }
  22. if err = d.client.RESTfulGet(c, d.statURI, ip, url.Values{}, &res, mid); err != nil {
  23. log.Error("statURI url(%s) mid(%d) error(%v)", d.statURI, mid, err)
  24. err = ecode.CreativeDataErr
  25. return
  26. }
  27. if res.Code != 0 {
  28. log.Error("data url(%s) res(%v)", d.statURI, res)
  29. err = ecode.CreativeDataErr
  30. return
  31. }
  32. st = res.Stat
  33. return
  34. }
  35. // TagsWithChecked get predict tag with checked mark.
  36. func (d *Dao) TagsWithChecked(c context.Context, mid int64, tid uint16, title, filename, desc, cover string, tagFrom int8) (t []*data.CheckedTag, err error) {
  37. params := url.Values{}
  38. t = make([]*data.CheckedTag, 0)
  39. params.Set("client_type", strconv.Itoa(int(tagFrom)))
  40. params.Set("typeid", strconv.Itoa(int(tid)))
  41. params.Set("title", title)
  42. params.Set("filename", filename)
  43. params.Set("desc", desc)
  44. params.Set("cover", cover)
  45. params.Set("mid", strconv.FormatInt(mid, 10))
  46. var res struct {
  47. Code int `json:"code"`
  48. Data struct {
  49. Tags []*data.CheckedTag `json:"tags"`
  50. } `json:"data"`
  51. }
  52. log.Info("TagsWithChecked url(%s)", d.tagV2URI+"?"+params.Encode())
  53. if err = d.client.Get(c, d.tagV2URI, "", params, &res); err != nil {
  54. log.Error("data url(%s) error(%v)", d.tagV2URI+"?"+params.Encode(), err)
  55. err = ecode.CreativeDataErr
  56. return
  57. }
  58. if res.Code != 0 {
  59. log.Error("data url(%s) res(%v)", d.tagV2URI+"?"+params.Encode(), res)
  60. err = ecode.CreativeDataErr
  61. return
  62. }
  63. t = res.Data.Tags
  64. return
  65. }
  66. // RecommendCovers get recommend covers from AI.
  67. func (d *Dao) RecommendCovers(c context.Context, mid int64, fns []string) (cvs []string, err error) {
  68. params := url.Values{}
  69. params.Set("mid", strconv.FormatInt(mid, 10))
  70. params.Set("filename", strings.Join(fns, ","))
  71. var res struct {
  72. Code int `json:"code"`
  73. Data []string `json:"data"`
  74. }
  75. if err = d.client.Get(c, d.coverBFSURI, "", params, &res); err != nil {
  76. log.Error("Covers url(%s) error(%v)", d.coverBFSURI+"?"+params.Encode(), err)
  77. err = ecode.CreativeDataErr
  78. return
  79. }
  80. if res.Code != 0 {
  81. log.Error("Covers url(%s) res(%v)", d.coverBFSURI+"?"+params.Encode(), res)
  82. err = ecode.CreativeDataErr
  83. return
  84. }
  85. cvs = res.Data
  86. return
  87. }