From 17c25c5128960638ee6b406fc92c51775a10f072 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 15 May 2024 10:16:57 +0800 Subject: [PATCH] by Robin at 20240515 --- .../contentaudit/imageaudit/control_block.go | 2 +- library/mediafiller/mediafiller.go | 50 +++++++++++++++++++ library/mediafiller/mediafillerhelper.go | 39 +++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/library/contentaudit/imageaudit/control_block.go b/library/contentaudit/imageaudit/control_block.go index ae7bf5a3..499def1b 100644 --- a/library/contentaudit/imageaudit/control_block.go +++ b/library/contentaudit/imageaudit/control_block.go @@ -43,7 +43,7 @@ func NewImageAuditTaskBatchControlBlock(tasks []*dbstruct.ImageAuditTask, batchI imageIndex, taskIndex = ctrlBlock.RecordImage(taskCtrlBlock, &mediaFillables, imageIndex, taskIndex) } - mediafiller.FillList(&gin.Context{}, mediaFillables) + mediafiller.FillListInternal(&gin.Context{}, mediaFillables) return ctrlBlock } diff --git a/library/mediafiller/mediafiller.go b/library/mediafiller/mediafiller.go index d1035266..51eeee32 100644 --- a/library/mediafiller/mediafiller.go +++ b/library/mediafiller/mediafiller.go @@ -50,6 +50,10 @@ func (p *MediaFiller) GetFileServerDomain() string { //return defaultMediaFiller.fileServerDomainName } +func (p *MediaFiller) GetInternalFileServerDomain() string { + return "https://wishpal-ironfan-media.oss-cn-hangzhou.aliyuncs.com/" +} + func FillEntity(ctx *gin.Context, entity MediaFillable) error { videoIds := entity.GetVideoIds() videoMap, err := getVideoMapByIds(ctx, videoIds) @@ -134,3 +138,49 @@ func FillList(ctx *gin.Context, list []MediaFillable) error { return nil } + +func FillListInternal(ctx *gin.Context, list []MediaFillable) error { + imageIds := make([]int64, 0) + videoIds := make([]int64, 0) + + for _, v := range list { + imageIds = append(imageIds, v.GetImageIds()...) + videoIds = append(videoIds, v.GetVideoIds()...) + } + + videoMap, err := getVideoMapByIds(ctx, videoIds) + if err != nil { + logger.Error("mediafiller component getVideoMapByIds failed : %v", err) + return err + } + + // 获取视频封面 + for _, v := range videoMap { + imageIds = append(imageIds, v.CoverId) + } + imageMap, err := getImageMapByIds(ctx, imageIds) + if err != nil { + logger.Error("mediafiller component getImageMapByIds failed : %v", err) + return err + } + + for _, v := range list { + + images := make([]*dbstruct.ToCImage, 0) + videos := make([]*dbstruct.ToCVideo, 0) + for _, imageId := range v.GetImageIds() { + if image, ok := imageMap[imageId]; ok { + images = append(images, transToCImageInternal(image)) + } + } + for _, videoId := range v.GetVideoIds() { + if video, ok := videoMap[videoId]; ok { + videos = append(videos, transToCVideoInternal(video, imageMap[video.CoverId])) + } + } + v.SetImages(images) + v.SetVideos(videos) + } + + return nil +} diff --git a/library/mediafiller/mediafillerhelper.go b/library/mediafiller/mediafillerhelper.go index d43f1d43..ae4774fe 100644 --- a/library/mediafiller/mediafillerhelper.go +++ b/library/mediafiller/mediafillerhelper.go @@ -79,3 +79,42 @@ func transToCVideo(video *dbstruct.Video, coverImg *dbstruct.Image) *dbstruct.To } return ret } + +// todo +func transToCImageInternal(image *dbstruct.Image) *dbstruct.ToCImage { + if image == nil { + return nil + } + + // 选择内存最小的图片 + imgSrcId := image.SelectMinSizeOssId() + + return &dbstruct.ToCImage{ + Id: image.Id, + W: image.W, + H: image.H, + Fmt: image.Fmt, + Urls: []string{defaultMediaFiller.GetInternalFileServerDomain() + imgSrcId}, + } +} + +// todo +func transToCVideoInternal(video *dbstruct.Video, coverImg *dbstruct.Image) *dbstruct.ToCVideo { + if video == nil { + return nil + } + ret := &dbstruct.ToCVideo{ + Id: video.Id, + Dur: video.Dur, + CoverUrls: []string{}, + Urls: []string{defaultMediaFiller.GetInternalFileServerDomain() + video.SrcId}, + } + if coverImg != nil { + ret.CoverW = coverImg.W + ret.CoverH = coverImg.H + ret.CoverFmt = coverImg.Fmt + imgSrcId := coverImg.SelectMinSizeOssId() + ret.CoverUrls = []string{defaultMediaFiller.GetInternalFileServerDomain() + imgSrcId} + } + return ret +}