From 1f5f5b57e095e6af1eb9305f7a5737377fa68e5f Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 20 May 2024 15:29:07 +0800 Subject: [PATCH] by Robin at 20240520 --- app/mix/service/apiservice.go | 8 ++++ .../service/apiservice_business_validation.go | 44 +++++++++++++++++++ app/mix/service/business_validator/auth.go | 36 +++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 6cb4cef4..7ef20e98 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1723,6 +1723,10 @@ func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateRe func (s *Service) ApiUpdateMoment(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk + if ec = s.ApiUpdateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { + return + } + req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid) err := _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{ @@ -2502,6 +2506,10 @@ func (s *Service) ApiCreateZoneMoment(ctx *gin.Context, req *zonemomentproto.Api func (s *Service) ApiUpdateZoneMoment(ctx *gin.Context, req *zonemomentproto.ApiUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneMomentSrvOk + if ec = s.ApiUpdateZoneMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeZoneMomentSrvOk { + return + } + zonemoment, err := _DefaultZoneMoment.GetById(ctx, req.ZoneMoment.GetId()) if err != nil { logger.Error("_DefaultZoneMoment GetById fail, req: %v, err: %v", util.ToJson(req), err) diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index 200c13a6..fb5492aa 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -531,6 +531,7 @@ func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentp ec = errcode.ErrCodeMomentSrvOk resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingMoment, _DefaultAccountPunishment.OpListByMidAndType). QueryMomentCreateTimes(_DefaultMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid). EnsureMomentCreateTimesNotReachedDailyUpperbound(). @@ -546,6 +547,22 @@ func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentp return } +func (s *Service) ApiUpdateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeMomentSrvOk + + resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp). + Validate(). + Collect() + ec, _ = resultList[0].(errcode.ErrCode) + if ec != errcode.ErrCodeOk { + logger.Error("ApiUpdateMomentBusinessValidate business validation failed!") + return + } + + return +} + func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zonemomentproto.ApiCreateReq) (ec errcode.ErrCode, accountpunishment *dbstruct.AccountPunishment) { ec = errcode.ErrCodeMomentSrvOk @@ -563,6 +580,7 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon QueryAccount(_DefaultAccount.OpListByMid). EnsureAccountExist(). EnsureIsThisRole(consts.Streamer). + EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType). EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange). @@ -580,6 +598,32 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon return } +func (s *Service) ApiUpdateZoneMomentBusinessValidate(ctx *gin.Context, req *zonemomentproto.ApiUpdateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeMomentSrvOk + + mediaVisibleRange := int64(0) + switch req.ZoneMoment.GetCType() { + case consts.ZoneMomentCType_Paid: + mediaVisibleRange = req.ZoneMoment.GetMediaVisibleRange() + } + + resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsThisRole(consts.Streamer). + EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp). + EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange). + Validate(). + Collect() + ec, _ = resultList[0].(errcode.ErrCode) + if ec != errcode.ErrCodeOk { + logger.Error("ApiUpdateZoneMomentBusinessValidate business validation failed!") + return + } + + return +} + // 代运营创建验证码 func (s *Service) ApiCreateZoneThirdPartnerBusinessValidate(ctx *gin.Context, req *zone_third_partner_proto.ApiCreateReq) (vericode *dbstruct.VeriCode, ec errcode.ErrCode) { ec = errcode.ErrCodeLoginSrvOk diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 46c17504..f8a866e7 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -562,6 +562,42 @@ func (l *AuthBusinessValidator) EnsureZoneCollaboratorIsNotZoneOwner(fun func(ct return l } +func (l *AuthBusinessValidator) EnsureMediaIsSuccessfullyUploaded(media *dbstruct.MediaComponent) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + + if len(media.GetImageIds()) > 0 { + imageIdForUploadFail, err := apollo.GetIntValue(consts.ImageIdForUploadFail, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + l.ec = errcode.ErrCodeApolloReadFail + return + } + for _, imageId := range media.GetImageIds() { + if int64(imageIdForUploadFail) == imageId { + l.ec = errcode.ErrCodeMediaUploadFail + return + } + } + } + + if len(media.GetVideoIds()) > 0 { + videoIdForUploadFail, err := apollo.GetIntValue(consts.VideoIdForUploadFail, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + l.ec = errcode.ErrCodeApolloReadFail + return + } + for _, videoId := range media.GetVideoIds() { + if int64(videoIdForUploadFail) == videoId { + l.ec = errcode.ErrCodeMediaUploadFail + return + } + } + } + }) + return l +} + // 执行校验 func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator { a.BusinessValidateStream.Validate()