From 460153a3949ee74a76d07914eada7595ef6e585e Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 18 Apr 2024 17:43:12 +0800 Subject: [PATCH] by Robin at 20240418 --- api/errcode/errcode.go | 2 ++ .../service/apiservice_business_validation.go | 5 +++-- app/mix/service/business_validator/auth.go | 17 +++++++++++++++++ app/mix/service/utilservice.go | 10 +++++++--- dbstruct/zonemoment.go | 14 ++++++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index 11174813..6839e127 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -177,6 +177,7 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeZoneMomentSrvFail: "私密圈动态服务错误", ErrCodeZoneMomentNotExist: "私密圈动态不存在", ErrCodePaidZoneMomentCreateTimesReachedUpperbound: "付费动态不能多于免费动态", + ErrCodeZoneMomentImagesNotEnoughForEncryption: "预览图片数不得大于等于上传图片数", ErrCodeZoneMomentThumbsUpSrvFail: "私密圈点赞服务错误", ErrCodeZoneMomentThumbsUpNotExist: "私密圈点赞不存在", @@ -445,6 +446,7 @@ const ( ErrCodeZoneMomentSrvFail ErrCode = -34001 // 私密圈动态服务错误 ErrCodeZoneMomentNotExist ErrCode = -34002 // 私密圈动态不存在 ErrCodePaidZoneMomentCreateTimesReachedUpperbound ErrCode = -34003 // 私密圈付费动态创建次数已达上限 + ErrCodeZoneMomentImagesNotEnoughForEncryption ErrCode = -34004 // 私密圈图片贴图片数量少于可预览图片数 // ZoneMomentThumbsUp: 35xxx ErrCodeZoneMomentThumbsUpSrvOk ErrCode = ErrCodeOk diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index cf323baf..5e34d7aa 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -549,7 +549,7 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon ec = errcode.ErrCodeMomentSrvOk pType := int64(0) - switch util.DerefInt64(req.ZoneMoment.CType) { + switch req.ZoneMoment.GetCType() { case consts.ZoneMomentCType_Free: pType = consts.AccountPunishment_BlockFromCreatingFreeZoneMoment case consts.ZoneMomentCType_Paid: @@ -563,7 +563,8 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType). EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid). - EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, util.DerefInt64(req.CType)). + EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()). + EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, req.ZoneMoment.GetMediaVisibleRange()). Validate(). Collect() ec, _ = resultList[0].(errcode.ErrCode) diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 9b2cf84d..90e95a15 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -437,6 +437,23 @@ func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperb return l } +func (l *AuthBusinessValidator) EnsureZoneMomentImagesEnoughForEncryption(mType int64, media *dbstruct.MediaComponent, mediaVisibleRange int64) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + + if mType == consts.MediaTypeVideo { + return + } + + if len(media.GetImageIds()) <= int(mediaVisibleRange) { + logger.Error("images of this zone moment are not enough for encryption") + l.ec = errcode.ErrCodeZoneMomentImagesNotEnoughForEncryption + return + } + }) + return l + +} + // 执行校验 func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator { a.BusinessValidateStream.Validate() diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 2383d551..01b37222 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -883,9 +883,13 @@ func (s *Service) utilUnThumbsZoneMoment(ctx *gin.Context, req *zonemomentproto. // 加密未解锁身份的动态 func (s *Service) utilEncryptInaccessibleZoneMoment(vo *zonemomentproto.ApiZoneMomentVO) { - if util.DerefInt64(vo.MType) == consts.MediaTypeImg { + if vo.GetMType() == consts.MediaTypeImg { imageIds := vo.MediaComp.GetImageIds() - mediaVisibleRange := util.DerefInt64(vo.MediaVisibleRange) + mediaVisibleRange := vo.GetMediaVisibleRange() + // 为0也至少下发一张图片 + if mediaVisibleRange == 0 { + mediaVisibleRange = 1 + } if len(imageIds) <= int(mediaVisibleRange) { return } @@ -907,7 +911,7 @@ func (s *Service) utilFillIsZoneMomentUnlocked(vo *zonemomentproto.ApiZoneMoment case consts.ZoneMomentCType_Paid: if vo.IsSuperfanshipUnlocked == consts.IsSuperfanshipUnlocked_Yes { // 超粉解锁 vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) - } else if util.DerefInt64(vo.IsIronfanVisible) == consts.IsIronfanVisible_Yes && vo.IsIronfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { // 铁粉可见 + } else if vo.GetIsIronfanVisible() == consts.IsIronfanVisible_Yes && vo.IsIronfanshipUnlocked == consts.IsIronfanshipUnlocked_Yes { // 铁粉可见 vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) } else if momentIdZmuMap[vo.ZoneMoment.GetId()].IsUnlock() { // 动态已购买 vo.SetIsZoneMomentUnlocked(consts.IsZoneMomentUnlocked_Yes) diff --git a/dbstruct/zonemoment.go b/dbstruct/zonemoment.go index 5a460fc8..b2983de2 100644 --- a/dbstruct/zonemoment.go +++ b/dbstruct/zonemoment.go @@ -67,6 +67,20 @@ func (p *ZoneMoment) GetCType() int64 { return 0 } +func (p *ZoneMoment) GetMediaVisibleRange() int64 { + if p != nil && p.MediaVisibleRange != nil { + return *p.MediaVisibleRange + } + return 0 +} + +func (p *ZoneMoment) GetIsIronfanVisible() int64 { + if p != nil && p.IsIronfanVisible != nil { + return *p.IsIronfanVisible + } + return 0 +} + func (p *ZoneMoment) GetUt() int64 { if p != nil && p.Ut != nil { return *p.Ut