service/library/mediafiller/mediafillerhelper.go

121 lines
2.8 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-03-08 15:49:32 +08:00
Urls: []string{defaultMediaFiller.GetFileServerDomain() + 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{},
2024-03-08 15:49:32 +08:00
Urls: []string{defaultMediaFiller.GetFileServerDomain() + video.SrcId},
2023-12-21 22:17:40 +08:00
}
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()
2024-03-08 15:49:32 +08:00
ret.CoverUrls = []string{defaultMediaFiller.GetFileServerDomain() + imgSrcId}
2023-12-30 12:43:58 +08:00
}
return ret
2023-12-21 22:17:40 +08:00
}
2024-05-15 10:16:57 +08:00
// 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
}