view.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package view
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/app-intl/model"
  6. "go-common/app/interface/main/app-intl/model/view"
  7. "go-common/app/service/main/archive/api"
  8. "go-common/app/service/main/archive/model/archive"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "go-common/library/net/metadata"
  12. "go-common/library/sync/errgroup"
  13. "go-common/library/text/translate/chinese"
  14. )
  15. const (
  16. // _descLen is.
  17. _descLen = 250
  18. // _avTypeAv is.
  19. _avTypeAv = 1
  20. // _businessLike is.
  21. _businessLike = "archive"
  22. )
  23. // View all view data.
  24. func (s *Service) View(c context.Context, mid, aid, movieID int64, plat int8, build int, ak, mobiApp, device, buvid, cdnIP, network, adExtra, from string, now time.Time, locale string) (v *view.View, err error) {
  25. if v, err = s.ViewPage(c, mid, aid, movieID, plat, build, ak, mobiApp, device, cdnIP, true, now, locale); err != nil {
  26. ip := metadata.String(c, metadata.RemoteIP)
  27. if err == ecode.AccessDenied || err == ecode.NothingFound {
  28. log.Warn("s.ViewPage() mid(%d) aid(%d) movieID(%d) plat(%d) ak(%s) ip(%s) cdn_ip(%s) error(%v)", mid, aid, movieID, plat, ak, ip, cdnIP, err)
  29. } else {
  30. log.Error("s.ViewPage() mid(%d) aid(%d) movieID(%d) plat(%d) ak(%s) ip(%s) cdn_ip(%s) error(%v)", mid, aid, movieID, plat, ak, ip, cdnIP, err)
  31. }
  32. return
  33. }
  34. isTW := model.TWLocale(locale)
  35. g, ctx := errgroup.WithContext(c)
  36. g.Go(func() (err error) {
  37. v.VIPActive = s.vipActiveCache[view.VIPActiveView]
  38. return
  39. })
  40. g.Go(func() (err error) {
  41. s.initReqUser(ctx, v, mid, plat, build)
  42. if v.AttrVal(archive.AttrBitIsPGC) != archive.AttrYes {
  43. s.initContributions(ctx, v, isTW)
  44. }
  45. return
  46. })
  47. g.Go(func() (err error) {
  48. s.initRelateCMTag(ctx, v, plat, build, mid, buvid, mobiApp, device, network, adExtra, from, now, isTW)
  49. return
  50. })
  51. if v.AttrVal(archive.AttrBitIsPGC) != archive.AttrYes {
  52. g.Go(func() (err error) {
  53. s.initDM(ctx, v)
  54. return
  55. })
  56. g.Go(func() (err error) {
  57. s.initAudios(ctx, v)
  58. return
  59. })
  60. if len([]rune(v.Desc)) > _descLen {
  61. g.Go(func() (err error) {
  62. if desc, _ := s.arcDao.Description(ctx, v.Aid); desc != "" {
  63. v.Desc = desc
  64. }
  65. return
  66. })
  67. }
  68. }
  69. if err = g.Wait(); err != nil {
  70. log.Error("%+v", err)
  71. }
  72. return
  73. }
  74. // ViewPage view page data.
  75. func (s *Service) ViewPage(c context.Context, mid, aid, movieID int64, plat int8, build int, ak, mobiApp, device, cdnIP string, nMovie bool, now time.Time, locale string) (v *view.View, err error) {
  76. if aid == 0 && movieID == 0 {
  77. err = ecode.NothingFound
  78. return
  79. }
  80. var (
  81. vs *view.ViewStatic
  82. vp *archive.View3
  83. seasoninfo map[int64]int64
  84. ok bool
  85. )
  86. if movieID != 0 {
  87. if seasoninfo, err = s.banDao.SeasonidAid(c, movieID, now); err != nil {
  88. log.Error("%+v", err)
  89. err = ecode.NothingFound
  90. return
  91. }
  92. if aid, ok = seasoninfo[movieID]; !ok || aid == 0 {
  93. err = ecode.NothingFound
  94. return
  95. }
  96. var a *api.Arc
  97. if a, err = s.arcDao.Archive3(c, aid); err != nil {
  98. log.Error("%+v", err)
  99. err = ecode.NothingFound
  100. return
  101. }
  102. if a == nil {
  103. err = ecode.NothingFound
  104. return
  105. }
  106. vs = &view.ViewStatic{Archive3: archive.BuildArchive3(a)}
  107. s.prom.Incr("from_movieID")
  108. } else {
  109. if vp, err = s.arcDao.ViewCache(c, aid); err != nil {
  110. log.Error("%+v", err)
  111. }
  112. if vp == nil || vp.Archive3 == nil || len(vp.Pages) == 0 || vp.AttrVal(archive.AttrBitIsMovie) == archive.AttrYes {
  113. if vp, err = s.arcDao.View3(c, aid); err != nil {
  114. log.Error("%+v", err)
  115. err = ecode.NothingFound
  116. return
  117. }
  118. }
  119. if vp == nil || vp.Archive3 == nil || len(vp.Pages) == 0 {
  120. err = ecode.NothingFound
  121. return
  122. }
  123. vs = &view.ViewStatic{Archive3: vp.Archive3}
  124. s.initPages(c, vs, vp.Pages)
  125. s.prom.Incr("from_aid")
  126. }
  127. isTW := model.TWLocale(locale)
  128. if isTW {
  129. out := chinese.Converts(c, vs.Title, vs.Desc)
  130. vs.Title = out[vs.Title]
  131. vs.Desc = out[vs.Desc]
  132. }
  133. // TODO fuck chanpin
  134. vs.Stat.DisLike = 0
  135. if s.overseaCheck(vs.Archive3, plat) {
  136. err = ecode.AreaLimit
  137. return
  138. }
  139. // check region area limit
  140. if err = s.areaLimit(c, plat, int16(vs.TypeID)); err != nil {
  141. return
  142. }
  143. v = &view.View{ViewStatic: vs, DMSeg: 1, PlayerIcon: s.playerIcon}
  144. if v.AttrVal(archive.AttrBitIsPGC) != archive.AttrYes {
  145. // check access
  146. if err = s.checkAceess(c, mid, v.Aid, int(v.State), int(v.Access), ak); err != nil {
  147. // archive is ForbitFixed and Transcoding and StateForbitDistributing need analysis history body .
  148. if v.State != archive.StateForbidFixed {
  149. return
  150. }
  151. err = nil
  152. }
  153. if v.Access > 0 {
  154. v.Stat.View = 0
  155. }
  156. }
  157. g, ctx := errgroup.WithContext(c)
  158. if mid != 0 {
  159. g.Go(func() (err error) {
  160. v.History, _ = s.arcDao.Progress(ctx, v.Aid, mid)
  161. return
  162. })
  163. }
  164. if v.AttrVal(archive.AttrBitIsPGC) == archive.AttrYes {
  165. if v.AttrVal(archive.AttrBitIsMovie) != archive.AttrYes {
  166. g.Go(func() error {
  167. return s.initPGC(ctx, v, mid, build, mobiApp, device)
  168. })
  169. } else {
  170. g.Go(func() error {
  171. return s.initMovie(ctx, v, mid, build, mobiApp, device, nMovie)
  172. })
  173. }
  174. } else {
  175. g.Go(func() (err error) {
  176. if err = s.initDownload(ctx, v, mid, cdnIP); err != nil {
  177. ip := metadata.String(ctx, metadata.RemoteIP)
  178. log.Error("aid(%d) mid(%d) ip(%s) cdn_ip(%s) error(%+v)", v.Aid, mid, ip, cdnIP, err)
  179. }
  180. return
  181. })
  182. }
  183. if err = g.Wait(); err != nil {
  184. log.Error("%+v", err)
  185. }
  186. return
  187. }