service/library/mediafiller/mediafillerhelper.go

121 lines
2.8 KiB
Go

package mediafiller
import (
"service/dbstruct"
"service/library/logger"
"github.com/gin-gonic/gin"
)
// todo
func getImageMapByIds(ctx *gin.Context, ids []int64) (map[int64]*dbstruct.Image, error) {
if len(ids) == 0 {
return nil, nil
}
list, err := defaultMediaFiller.getImageByIds(ctx, ids)
if err != nil {
logger.Error("defaultMediaFiller getImageByIds failed : %v", err)
return nil, err
}
imageMap := make(map[int64]*dbstruct.Image, len(list))
for _, image := range list {
imageMap[image.Id] = image
}
return imageMap, err
}
// todo
func getVideoMapByIds(ctx *gin.Context, ids []int64) (map[int64]*dbstruct.Video, error) {
if len(ids) == 0 {
return nil, nil
}
list, err := defaultMediaFiller.getVideoByIds(ctx, ids)
if err != nil {
logger.Error("defaultMediaFiller getVideoByIds failed : %v", err)
return nil, err
}
videoMap := make(map[int64]*dbstruct.Video, len(list))
for _, video := range list {
videoMap[video.Id] = video
}
return videoMap, err
}
// todo
func transToCImage(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.GetFileServerDomain() + imgSrcId},
}
}
// todo
func transToCVideo(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.SrcId},
}
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 {
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
}