service/library/mediafiller/mediafillerhelper.go

82 lines
1.9 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
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
}
2024-02-06 02:51:24 +08:00
// 选择内存最小的图片
imgSrcId := image.SelectMinSizeOssId()
2023-12-21 22:17:40 +08:00
return &dbstruct.ToCImage{
Id: image.Id,
W: image.W,
H: image.H,
Fmt: image.Fmt,
2024-02-06 02:51:24 +08:00
Urls: []string{defaultMediaFiller.fileServerDomainName + imgSrcId},
2023-12-21 22:17:40 +08:00
}
}
// todo
2023-12-30 12:43:58 +08:00
func transToCVideo(video *dbstruct.Video, coverImg *dbstruct.Image) *dbstruct.ToCVideo {
2023-12-21 22:17:40 +08:00
if video == nil {
return nil
}
2023-12-30 12:43:58 +08:00
ret := &dbstruct.ToCVideo{
2023-12-21 22:17:40 +08:00
Id: video.Id,
Dur: video.Dur,
2023-12-30 12:43:58 +08:00
CoverUrls: []string{},
2023-12-21 22:17:40 +08:00
Urls: []string{defaultMediaFiller.fileServerDomainName + video.SrcId},
}
2023-12-30 12:43:58 +08:00
if coverImg != nil {
2024-01-16 21:44:58 +08:00
ret.CoverW = coverImg.W
ret.CoverH = coverImg.H
ret.CoverFmt = coverImg.Fmt
2024-02-06 02:51:24 +08:00
imgSrcId := coverImg.SelectMinSizeOssId()
ret.CoverUrls = []string{defaultMediaFiller.fileServerDomainName + imgSrcId}
2023-12-30 12:43:58 +08:00
}
return ret
2023-12-21 22:17:40 +08:00
}