video.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/common"
  5. video "go-common/app/service/bbq/video/api/grpc/v1"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // BatchVideoInfo .
  10. func (d *Dao) BatchVideoInfo(c context.Context, svids []int64) (res map[int64]*video.VideoInfo, err error) {
  11. res = make(map[int64]*video.VideoInfo)
  12. videoReq := &video.ListVideoInfoRequest{SvIDs: svids}
  13. reply, err := d.videoClient.ListVideoInfo(c, videoReq)
  14. if err != nil {
  15. log.Errorw(c, "log", "call video service list vidoe info fail", "req", videoReq.String())
  16. return
  17. }
  18. for _, videoInfo := range reply.List {
  19. res[videoInfo.VideoBase.Svid] = videoInfo
  20. }
  21. log.V(10).Infow(c, "log", "batch video base", "video_info", res)
  22. return
  23. }
  24. // VideoBase 获取单个svid的VideoBase,不存在则会返回error
  25. func (d *Dao) VideoBase(c context.Context, mid, svid int64) (res *video.VideoBase, err error) {
  26. videoInfos, err := d.BatchVideoInfo(c, []int64{svid})
  27. if err != nil {
  28. log.Warnw(c, "log", "batch fetch video info fail", "mid", mid, "svid", svid)
  29. return
  30. }
  31. if len(videoInfos) == 0 {
  32. err = ecode.VideoUnExists
  33. log.Warnw(c, "log", "get empty video base", "mid", mid, "svid", svid)
  34. return
  35. }
  36. videoInfo, exists := videoInfos[svid]
  37. if !exists {
  38. err = ecode.VideoUnExists
  39. log.Infow(c, "log", "get empty video base", "mid", mid, "svid", svid)
  40. return
  41. }
  42. res = videoInfo.VideoBase
  43. if res.State == common.VideoStPassReviewReject {
  44. log.Infow(c, "log", "video state in audit", "mid", mid, "svid", svid, "video_base", res)
  45. err = ecode.VideoInAudit
  46. return
  47. }
  48. if !common.IsSvStateAvailable(res.State) {
  49. err = ecode.VideoUnReachable
  50. log.Infow(c, "log", "video state not available", "mid", mid, "svid", svid, "video_base", res)
  51. return
  52. }
  53. if res.State == common.VideoStPassReviewReject && mid != res.Mid {
  54. err = ecode.VideoUnReachable
  55. log.Infow(c, "log", "video state only owner available", "mid", mid, "svid", svid, "video_base", res)
  56. return
  57. }
  58. return
  59. }