From d1921bdab56ce172cc14ee251c887fedbce4f284 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 11 Oct 2024 15:24:06 +0800 Subject: [PATCH] by Robin at 20241011 --- api/errcode/errcode.go | 16 +++++++++------- .../service/apiservice_business_validation.go | 4 ++++ app/mix/service/business_validator/auth.go | 11 +++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index ccd11c82..f1f91ac5 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -142,9 +142,10 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeHandleWsFail: "", - ErrCodeMediaSrvFail: "媒体服务错误", - ErrCodeMediaNotExist: "媒体不存在", - ErrCodeMediaUploadFail: "媒体上传失败", + ErrCodeMediaSrvFail: "媒体服务错误", + ErrCodeMediaNotExist: "媒体不存在", + ErrCodeMediaUploadFail: "媒体上传失败", + ErrCodeMediaVideoMustBeUnique: "只能上传一个视频,请删除多余视频", ErrCodeImageAuditTaskSrvFail: "图像审核任务服务错误", ErrCodeImageAuditTaskNotExist: "图像审核任务不存在", @@ -584,10 +585,11 @@ const ( ErrCodeVideoModerationNotExist ErrCode = -44002 // 视频审核不存在 // Media: 60xxx - ErrCodeMediaSrvOk ErrCode = ErrCodeOk - ErrCodeMediaSrvFail ErrCode = -60001 // 媒体服务错误 - ErrCodeMediaNotExist ErrCode = -60002 // 媒体不存在 - ErrCodeMediaUploadFail ErrCode = -60003 // 媒体上传失败 + ErrCodeMediaSrvOk ErrCode = ErrCodeOk + ErrCodeMediaSrvFail ErrCode = -60001 // 媒体服务错误 + ErrCodeMediaNotExist ErrCode = -60002 // 媒体不存在 + ErrCodeMediaUploadFail ErrCode = -60003 // 媒体上传失败 + ErrCodeMediaVideoMustBeUnique ErrCode = -60004 // 视频必须唯一 // Hvyogo: 61xxx ErrCodeHvyogoSrvOk ErrCode = ErrCodeOk diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index c7d5101b..b57ab42c 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -590,6 +590,7 @@ func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentp QueryAccount(_DefaultAccount.OpListByMid). EnsureAccountExist(). EnsureIsThisRole(consts.Streamer). + EnsureVideoIsUnique(req.Moment.MediaComp). EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingMoment, _DefaultAccountPunishment.OpListByMidAndType). QueryMomentCreateTimes(_DefaultMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid). @@ -614,6 +615,7 @@ func (s *Service) ApiUpdateMomentBusinessValidate(ctx *gin.Context, req *momentp QueryAccount(_DefaultAccount.OpListByMid). EnsureAccountExist(). EnsureIsThisRole(consts.Streamer). + EnsureVideoIsUnique(req.Moment.MediaComp). EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp). Validate(). Collect() @@ -643,6 +645,7 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon QueryAccount(_DefaultAccount.OpListByMid). EnsureAccountExist(). EnsureIsThisRole(consts.Streamer). + EnsureVideoIsUnique(req.ZoneMoment.MediaComp). EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType). EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType). @@ -675,6 +678,7 @@ func (s *Service) ApiUpdateZoneMomentBusinessValidate(ctx *gin.Context, req *zon QueryAccount(_DefaultAccount.OpListByMid). EnsureAccountExist(). EnsureIsThisRole(consts.Streamer). + EnsureVideoIsUnique(req.ZoneMoment.MediaComp). EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp). EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange). Validate(). diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 985da84a..da67ff4c 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -726,6 +726,17 @@ func (l *AuthBusinessValidator) EnsureMediaIsSuccessfullyUploaded(media *dbstruc return l } +func (l *AuthBusinessValidator) EnsureVideoIsUnique(media *dbstruct.MediaComponent) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + if len(media.GetVideoIds()) > 0 { + if len(media.GetVideoIds()) > 1 { + l.ec = errcode.ErrCodeMediaVideoMustBeUnique + } + } + }) + return l +} + func (l *AuthBusinessValidator) EnsureStreamerAuthApprovalBasicCreated(fun func(*gin.Context, int64) (*dbstruct.StreamerAuthApprovalBasic, error), mid int64) *AuthBusinessValidator { l.oplist = append(l.oplist, func() { streamerauthapprovalbasic, err := fun(l.ctx, mid)