fix fill media
This commit is contained in:
parent
eea29e86ec
commit
2421f038e6
|
@ -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"` // 视频时
|
||||
|
|
|
@ -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,9 +101,13 @@ func FillEntity(ctx *gin.Context, entity MediaFillable) error {
|
|||
}
|
||||
for _, videoId := range videoIds {
|
||||
if video, ok := videoMap[videoId]; ok {
|
||||
if TestMidMap[baseReq.Mid] {
|
||||
videos = append(videos, transToCVideoTest(video, imageMap[video.CoverId]))
|
||||
} else {
|
||||
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.SetImages(images)
|
||||
entity.SetVideos(videos)
|
||||
|
||||
|
@ -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,9 +162,13 @@ func FillList(ctx *gin.Context, list []MediaFillable) error {
|
|||
}
|
||||
for _, videoId := range v.GetVideoIds() {
|
||||
if video, ok := videoMap[videoId]; ok {
|
||||
if TestMidMap[baseReq.Mid] {
|
||||
videos = append(videos, transToCVideoTest(video, imageMap[video.CoverId]))
|
||||
} else {
|
||||
videos = append(videos, transToCVideo(video, imageMap[video.CoverId]))
|
||||
}
|
||||
}
|
||||
}
|
||||
v.SetImages(images)
|
||||
v.SetVideos(videos)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue