subtitle_check.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/interface/main/dm2/model"
  6. account "go-common/app/service/main/account/api"
  7. archive "go-common/app/service/main/archive/model/archive"
  8. memberMdl "go-common/app/service/main/member/model/block"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. )
  12. const (
  13. _subtitleMaxLength = 50 * 10000
  14. )
  15. func (s *Service) checkAidOid(c context.Context, aid, oid int64) (err error) {
  16. if _, err = s.arcRPC.Video3(c, &archive.ArgVideo2{
  17. Aid: aid,
  18. Cid: oid,
  19. }); err != nil {
  20. log.Error("Video3(aid:%v,oid:%v),error(%v)", aid, oid, err)
  21. err = ecode.RequestErr
  22. return
  23. }
  24. return
  25. }
  26. func (s *Service) checkSubtitleLan(c context.Context, lan string) (err error) {
  27. if s.subtitleLans.GetByLan(lan) <= 0 {
  28. err = ecode.SubtitleIllegalLanguage
  29. return
  30. }
  31. return
  32. }
  33. func (s *Service) checkSubtitlePermission(c context.Context, aid, oid int64, tp int32, mid int64, subject *model.Subject) (err error) {
  34. if err = s.checkAudienceDraftAdd(c, aid, oid, tp, mid, subject); err != nil {
  35. log.Error("params(oid:%v, tp:%v, mid:%v,subject:%+v).err(%v)", oid, tp, mid, subject, err)
  36. return
  37. }
  38. return
  39. }
  40. func (s *Service) checkSubtitleData(c context.Context, aid, oid int64, data []byte) (detectErrs []*model.SubtitleDetectError, err error) {
  41. var (
  42. subtitleBody *model.SubtitleBody
  43. duration int64
  44. )
  45. if len(data) > _subtitleMaxLength {
  46. err = ecode.SubtitleSizeLimit
  47. return
  48. }
  49. if err = json.Unmarshal(data, &subtitleBody); err != nil {
  50. err = ecode.SubtitleUnValid
  51. return
  52. }
  53. if duration, err = s.videoDuration(c, aid, oid); err != nil {
  54. return
  55. }
  56. if duration <= 0 {
  57. err = ecode.SubtitleTimeUnValid
  58. return
  59. }
  60. if detectErrs, err = subtitleBody.CheckItem(duration); err != nil {
  61. return
  62. }
  63. return
  64. }
  65. func (s *Service) checkSubtitleLocked(c context.Context, submit bool, oid int64, tp int32, lan string, mid int64) (err error) {
  66. var (
  67. lockSubtitle *model.Subtitle
  68. )
  69. if !submit {
  70. return
  71. }
  72. if lockSubtitle, err = s.isSubtitleLanLock(c, oid, tp, lan); err != nil {
  73. log.Error("params(oid:%v, tp:%v) error(%v)", oid, tp, err)
  74. return
  75. }
  76. if lockSubtitle != nil && lockSubtitle.IsLock && lockSubtitle.UpMid != mid && lockSubtitle.Mid != mid {
  77. err = ecode.SubtileLanLocked
  78. return
  79. }
  80. return
  81. }
  82. func (s *Service) checkSubtitleAuthor(c context.Context, oid, subtitleID int64, lan string, mid int64) (authorID int64, err error) {
  83. var (
  84. originSubtitle *model.Subtitle
  85. originLan int64
  86. )
  87. if subtitleID <= 0 {
  88. authorID = mid
  89. return
  90. }
  91. if originSubtitle, err = s.getSubtitle(c, oid, subtitleID); err != nil {
  92. return
  93. }
  94. if originSubtitle == nil {
  95. err = ecode.NothingFound
  96. return
  97. }
  98. if originSubtitle.Status != model.SubtitleStatusAuditBack &&
  99. originSubtitle.Status != model.SubtitleStatusPublish &&
  100. originSubtitle.Status != model.SubtitleStatusCheckPublish &&
  101. originSubtitle.Status != model.SubtitleStatusManagerBack {
  102. err = ecode.SubtitleOriginUnValid
  103. return
  104. }
  105. if originLan = s.subtitleLans.GetByLan(lan); originLan <= 0 || originLan != int64(originSubtitle.Lan) {
  106. err = ecode.SubtitleIllegalLanguage
  107. return
  108. }
  109. authorID = originSubtitle.AuthorID
  110. return
  111. }
  112. func (s *Service) checkAudienceDraftAdd(c context.Context, aid, oid int64, tp int32, mid int64, subject *model.Subject) (err error) {
  113. var (
  114. profileReply *account.ProfileReply
  115. blackReply *account.BlacksReply
  116. blockInfo *memberMdl.RPCResInfo
  117. resDm []*model.UpFilter
  118. allow bool
  119. closed bool
  120. subtitleSubject *model.SubtitleSubject
  121. )
  122. if subtitleSubject, err = s.subtitleSubject(c, aid); err != nil {
  123. log.Error("subtitleSubject(aid:%v) error(%v)", aid, err)
  124. err = nil
  125. }
  126. if subtitleSubject != nil {
  127. allow = subtitleSubject.Allow
  128. closed = subtitleSubject.AttrVal(model.AttrSubtitleClose) == model.AttrYes
  129. }
  130. if closed {
  131. err = ecode.SubtitleDenied
  132. return
  133. }
  134. if subject.Mid == mid {
  135. return
  136. }
  137. if !allow {
  138. err = ecode.SubtitleDenied
  139. return
  140. }
  141. // 视频观众可以投稿
  142. // 账号绑定手机号
  143. if profileReply, err = s.accountRPC.Profile3(c, &account.MidReq{
  144. Mid: mid,
  145. }); err != nil {
  146. log.Error("accRPC.UserInfo(%v) error(%v)", mid, err)
  147. return
  148. }
  149. if profileReply.GetProfile().GetIdentification() == 0 && profileReply.GetProfile().GetTelStatus() == 0 {
  150. err = ecode.UserCheckNoPhone
  151. return
  152. }
  153. if profileReply.GetProfile().GetIdentification() == 0 && profileReply.GetProfile().GetTelStatus() == 2 {
  154. err = ecode.UserCheckInvalidPhone
  155. return
  156. }
  157. if profileReply.GetProfile().GetTelStatus() == 0 {
  158. err = ecode.UserCheckInvalidPhone
  159. return
  160. }
  161. // 用户等级大于2
  162. if profileReply.GetProfile().GetLevel() < 2 {
  163. err = ecode.UserLevelLow
  164. return
  165. }
  166. // 账号被拉黑
  167. if blackReply, err = s.accountRPC.Blacks3(c, &account.MidReq{
  168. Mid: subject.Mid,
  169. }); err != nil {
  170. log.Error("params(arg:%+v).err(%v)", subject.Mid, err)
  171. return
  172. }
  173. if _, ok := blackReply.GetBlackList()[mid]; ok {
  174. err = ecode.SubtitleUserBalcked
  175. return
  176. }
  177. if resDm, err = s.UpFilters(c, subject.Mid); err != nil {
  178. log.Error("params(mid:%+v).err(%v)", subject.Mid, err)
  179. return
  180. }
  181. hash := model.Hash(mid, 0)
  182. for _, uf := range resDm {
  183. if uf.Filter == hash {
  184. err = ecode.SubtitleUserBalcked
  185. return
  186. }
  187. }
  188. // 账号被封禁
  189. if blockInfo, err = s.memberRPC.BlockInfo(c, &memberMdl.RPCArgInfo{
  190. MID: mid,
  191. }); err != nil {
  192. log.Error("params(arg:%+v).err(%v)", mid, err)
  193. return
  194. }
  195. if blockInfo.BlockStatus != memberMdl.BlockStatusFalse {
  196. err = ecode.UserDisabled
  197. return
  198. }
  199. return
  200. }