by Robin at 20240515

This commit is contained in:
Leufolium 2024-05-15 10:16:57 +08:00
parent 6dc7bf2d66
commit 17c25c5128
3 changed files with 90 additions and 1 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}