fix fill media

This commit is contained in:
lwl0608 2024-09-10 18:43:55 +08:00
parent eea29e86ec
commit 2421f038e6
3 changed files with 69 additions and 2 deletions

View File

@ -184,6 +184,16 @@ func (i *Video) SelectMinSizeOssId() string {
return i.SrcId
}
func (i *Video) MustSelectMinSizeOssId() string {
if i == nil {
return ""
}
if i.Status == VideoStatusResizeDone && len(i.SrcId720) > 0 && i.Size720 < i.SizeSrc {
return i.SrcId720
}
return i.SrcId
}
type ToCVideo struct {
Id int64 `json:"id"` // 视频id
Dur int64 `json:"dur"` // 视频时

View File

@ -1,7 +1,9 @@
package mediafiller
import (
"encoding/json"
"math/rand"
"service/api/proto/gateway/proto"
"service/dbstruct"
"service/library/logger"
"time"
@ -9,6 +11,11 @@ import (
"github.com/gin-gonic/gin"
)
var TestMidMap = map[int64]bool{
161: true,
1: true,
}
func init() {
rand.Seed(time.Now().Unix())
}
@ -55,6 +62,17 @@ func (p *MediaFiller) GetInternalFileServerDomain() string {
}
func FillEntity(ctx *gin.Context, entity MediaFillable) error {
baseReq := proto.BaseReq{}
var bodyBytes []byte
body, ok := ctx.Get(gin.BodyBytesKey)
if ok {
bodyBytes = body.([]byte)
}
_ = json.Unmarshal(bodyBytes, &baseReq)
if TestMidMap[baseReq.Mid] {
logger.Info("FillTest req: %v", string(bodyBytes))
}
videoIds := entity.GetVideoIds()
videoMap, err := getVideoMapByIds(ctx, videoIds)
if err != nil {
@ -83,7 +101,11 @@ func FillEntity(ctx *gin.Context, entity MediaFillable) error {
}
for _, videoId := range videoIds {
if video, ok := videoMap[videoId]; ok {
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
if TestMidMap[baseReq.Mid] {
videos = append(videos, transToCVideoTest(video, imageMap[video.CoverId]))
} else {
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
}
}
}
entity.SetImages(images)
@ -94,6 +116,17 @@ func FillEntity(ctx *gin.Context, entity MediaFillable) error {
}
func FillList(ctx *gin.Context, list []MediaFillable) error {
baseReq := proto.BaseReq{}
var bodyBytes []byte
body, ok := ctx.Get(gin.BodyBytesKey)
if ok {
bodyBytes = body.([]byte)
}
_ = json.Unmarshal(bodyBytes, &baseReq)
if TestMidMap[baseReq.Mid] {
logger.Info("FillTest req: %v", string(bodyBytes))
}
imageIds := make([]int64, 0)
videoIds := make([]int64, 0)
@ -129,7 +162,11 @@ func FillList(ctx *gin.Context, list []MediaFillable) error {
}
for _, videoId := range v.GetVideoIds() {
if video, ok := videoMap[videoId]; ok {
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
if TestMidMap[baseReq.Mid] {
videos = append(videos, transToCVideoTest(video, imageMap[video.CoverId]))
} else {
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
}
}
}
v.SetImages(images)

View File

@ -80,6 +80,26 @@ func transToCVideo(video *dbstruct.Video, coverImg *dbstruct.Image) *dbstruct.To
return ret
}
func transToCVideoTest(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.GetFileServerDomain() + video.MustSelectMinSizeOssId()},
}
if coverImg != nil {
ret.CoverW = coverImg.W
ret.CoverH = coverImg.H
ret.CoverFmt = coverImg.Fmt
imgSrcId := coverImg.SelectMinSizeOssId()
ret.CoverUrls = []string{defaultMediaFiller.GetFileServerDomain() + imgSrcId}
}
return ret
}
// todo
func transToCImageInternal(image *dbstruct.Image) *dbstruct.ToCImage {
if image == nil {