service/library/mediafiller/mediafillerhelper.go

70 lines
1.5 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
}
return &dbstruct.ToCImage{
Id: image.Id,
W: image.W,
H: image.H,
Fmt: image.Fmt,
Urls: []string{defaultMediaFiller.fileServerDomainName + image.SrcId},
}
}
// todo
func transToCVideo(video *dbstruct.Video) *dbstruct.ToCVideo {
if video == nil {
return nil
}
return &dbstruct.ToCVideo{
Id: video.Id,
Dur: video.Dur,
CoverUrls: []string{"todo"},
Urls: []string{defaultMediaFiller.fileServerDomainName + video.SrcId},
}
}