rpc.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package server
  2. import (
  3. "go-common/app/interface/main/dm2/conf"
  4. "go-common/app/interface/main/dm2/model"
  5. "go-common/app/interface/main/dm2/service"
  6. "go-common/library/ecode"
  7. "go-common/library/net/rpc"
  8. "go-common/library/net/rpc/context"
  9. )
  10. // RPC rpc server.
  11. type RPC struct {
  12. s *service.Service
  13. }
  14. // New new a rpc server.
  15. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  16. r := &RPC{s: s}
  17. svr = rpc.NewServer(c.RPCServer)
  18. if err := svr.Register(r); err != nil {
  19. panic(err)
  20. }
  21. return
  22. }
  23. // Auth check connection success.
  24. func (r *RPC) Auth(c context.Context, arg *rpc.Auth, res *struct{}) (err error) {
  25. return
  26. }
  27. // Ping checks connection success.
  28. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  29. return
  30. }
  31. // SubjectInfos multi get dm subject info by type and oids.
  32. func (r *RPC) SubjectInfos(c context.Context, a *model.ArgOids, res *map[int64]*model.SubjectInfo) (err error) {
  33. *res, err = r.s.SubjectInfos(c, a.Type, a.Plat, a.Oids)
  34. return
  35. }
  36. // EditDMState edit dm state.
  37. func (r *RPC) EditDMState(c context.Context, a *model.ArgEditDMState, res *struct{}) (err error) {
  38. err = r.s.EditDMState(c, a.Type, a.Mid, a.Oid, a.State, a.Dmids, a.Source, a.OperatorType)
  39. return
  40. }
  41. // EditDMPool edit dm pool.
  42. func (r *RPC) EditDMPool(c context.Context, a *model.ArgEditDMPool, res *struct{}) (err error) {
  43. err = r.s.EditDMPool(c, a.Type, a.Mid, a.Oid, a.Pool, a.Dmids, a.Source, a.OperatorType)
  44. return
  45. }
  46. // EditDMAttr edit dm attr
  47. func (r *RPC) EditDMAttr(c context.Context, a *model.ArgEditDMAttr, res *struct{}) (err error) {
  48. _, err = r.s.EditDMAttr(c, a.Type, a.Mid, a.Oid, a.Bit, a.Value, a.Dmids, a.Source, a.OperatorType)
  49. return
  50. }
  51. // BuyAdvance 购买高级弹幕
  52. func (r *RPC) BuyAdvance(c context.Context, a *model.ArgAdvance, res *struct{}) (err error) {
  53. err = r.s.BuyAdvance(c, a.Mid, a.Cid, a.Mode)
  54. return
  55. }
  56. // AdvanceState 高级弹幕状态
  57. func (r *RPC) AdvanceState(c context.Context, a *model.ArgAdvance, res *model.AdvState) (err error) {
  58. var v *model.AdvState
  59. if v, err = r.s.AdvanceState(c, a.Mid, a.Cid, a.Mode); err == nil {
  60. *res = *v
  61. }
  62. return
  63. }
  64. // Advances 高级弹幕申请列表
  65. func (r *RPC) Advances(c context.Context, a *model.ArgMid, res *[]*model.Advance) (err error) {
  66. *res, err = r.s.Advances(c, a.Mid)
  67. return
  68. }
  69. // PassAdvance 通过高级弹幕申请
  70. func (r *RPC) PassAdvance(c context.Context, a *model.ArgUpAdvance, res *struct{}) (err error) {
  71. err = r.s.PassAdvance(c, a.Mid, a.ID)
  72. return
  73. }
  74. // DenyAdvance 拒绝高级弹幕申请
  75. func (r *RPC) DenyAdvance(c context.Context, a *model.ArgUpAdvance, res *struct{}) (err error) {
  76. err = r.s.DenyAdvance(c, a.Mid, a.ID)
  77. return
  78. }
  79. // CancelAdvance 取消高级弹幕申请
  80. func (r *RPC) CancelAdvance(c context.Context, a *model.ArgUpAdvance, res *struct{}) (err error) {
  81. err = r.s.CancelAdvance(c, a.Mid, a.ID)
  82. return
  83. }
  84. // AddUserFilters add user filter.
  85. func (r *RPC) AddUserFilters(c context.Context, a *model.ArgAddUserFilters, res *[]*model.UserFilter) (err error) {
  86. fltMap := make(map[string]string)
  87. for _, filter := range a.Filters {
  88. fltMap[filter] = a.Comment
  89. }
  90. *res, err = r.s.AddUserFilters(c, a.Mid, a.Type, fltMap)
  91. return
  92. }
  93. // UserFilters multi get user filters.
  94. func (r *RPC) UserFilters(c context.Context, a *model.ArgMid, res *[]*model.UserFilter) (err error) {
  95. *res, err = r.s.UserFilters(c, a.Mid)
  96. return
  97. }
  98. // DelUserFilters delete user filters by filter id.
  99. func (r *RPC) DelUserFilters(c context.Context, a *model.ArgDelUserFilters, affect *int64) (err error) {
  100. *affect, err = r.s.DelUserFilters(c, a.Mid, a.IDs)
  101. return
  102. }
  103. // AddUpFilters add up filters.
  104. func (r *RPC) AddUpFilters(c context.Context, a *model.ArgAddUpFilters, res *struct{}) (err error) {
  105. fltMap := make(map[string]string)
  106. for _, filter := range a.Filters {
  107. fltMap[filter] = "" // NOTE here should be comment assignment
  108. }
  109. err = r.s.AddUpFilters(c, a.Mid, a.Type, fltMap)
  110. return
  111. }
  112. // UpFilters multi get up filters.
  113. func (r *RPC) UpFilters(c context.Context, a *model.ArgUpFilters, res *[]*model.UpFilter) (err error) {
  114. *res, err = r.s.UpFilters(c, a.Mid)
  115. return
  116. }
  117. // BanUsers ban user by upper or assist.
  118. func (r *RPC) BanUsers(c context.Context, a *model.ArgBanUsers, res *struct{}) (err error) {
  119. err = r.s.BanUsers(c, a.Mid, a.Oid, a.DMIDs)
  120. return
  121. }
  122. // CancelBanUsers cancel users by upper or assiat.
  123. func (r *RPC) CancelBanUsers(c context.Context, a *model.ArgCancelBanUsers, res *struct{}) (err error) {
  124. err = r.s.CancelBanUsers(c, a.Mid, a.Aid, a.Filters)
  125. return
  126. }
  127. // EditUpFilters edit upper filters.
  128. func (r *RPC) EditUpFilters(c context.Context, a *model.ArgEditUpFilters, res *int64) (err error) {
  129. *res, err = r.s.EditUpFilters(c, a.Mid, a.Type, a.Active, a.Filters)
  130. return
  131. }
  132. // AddGlobalFilter add global filters.
  133. func (r *RPC) AddGlobalFilter(c context.Context, a *model.ArgAddGlobalFilter, res *model.GlobalFilter) (err error) {
  134. var v *model.GlobalFilter
  135. if v, err = r.s.AddGlobalFilter(c, a.Type, a.Filter); err == nil {
  136. *res = *v
  137. }
  138. return
  139. }
  140. // GlobalFilters multi get global filters.
  141. func (r *RPC) GlobalFilters(c context.Context, a *model.ArgGlobalFilters, res *[]*model.GlobalFilter) (err error) {
  142. if a == nil {
  143. err = ecode.RequestErr
  144. return
  145. }
  146. *res, err = r.s.GlobalFilters(c)
  147. return
  148. }
  149. // DelGlobalFilters delete global filter.
  150. func (r *RPC) DelGlobalFilters(c context.Context, a *model.ArgDelGlobalFilters, affect *int64) (err error) {
  151. *affect, err = r.s.DelGlobalFilters(c, a.IDs)
  152. return
  153. }
  154. // Mask get web mask.
  155. func (r *RPC) Mask(c context.Context, a *model.ArgMask, res *model.Mask) (err error) {
  156. if a == nil {
  157. err = ecode.RequestErr
  158. return
  159. }
  160. var m *model.Mask
  161. if m, err = r.s.MaskList(c, a.Cid, a.Plat); err == nil && m != nil {
  162. *res = *m
  163. }
  164. return
  165. }
  166. // SubtitleGet .
  167. func (r *RPC) SubtitleGet(c context.Context, arg *model.ArgSubtitleGet, res *model.VideoSubtitles) (err error) {
  168. var v *model.VideoSubtitles
  169. if v, err = r.s.GetWebVideoSubtitle(c, arg.Aid, arg.Oid, arg.Type); err == nil {
  170. *res = *v
  171. }
  172. return
  173. }
  174. // SubtitleSujectSubmit set archive allow submit
  175. func (r *RPC) SubtitleSujectSubmit(c context.Context, arg *model.ArgSubtitleAllowSubmit, res *struct{}) (err error) {
  176. err = r.s.SubtitleSubjectSubmit(c, arg.Aid, arg.AllowSubmit, arg.Lan)
  177. return
  178. }
  179. // SubtitleSubjectSubmitGet get archive allow submit
  180. func (r *RPC) SubtitleSubjectSubmitGet(c context.Context, arg *model.ArgArchiveID, res *model.SubtitleSubjectReply) (err error) {
  181. var (
  182. reply *model.SubtitleSubjectReply
  183. )
  184. reply, err = r.s.SubtitleSubject(c, arg.Aid)
  185. *res = *reply
  186. return
  187. }