cdn test
This commit is contained in:
parent
fe3e1c35be
commit
93048a1a4b
|
@ -1,12 +1,18 @@
|
|||
package mediafiller
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"service/dbstruct"
|
||||
"service/library/logger"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
var defaultMediaFiller *MediaFiller
|
||||
|
||||
type GetImageByIdsFunc func(ctx *gin.Context, ids []int64) ([]*dbstruct.Image, error)
|
||||
|
@ -34,6 +40,14 @@ func SetFileServerDomainName(fileServerDomainName string) {
|
|||
defaultMediaFiller.fileServerDomainName = fileServerDomainName
|
||||
}
|
||||
|
||||
func (p *MediaFiller) GetFileServerDomain() string {
|
||||
// cdn测试
|
||||
if rand.Intn(100) < 20 {
|
||||
return "https://filecdn01.tiefen.fun/"
|
||||
}
|
||||
return defaultMediaFiller.fileServerDomainName
|
||||
}
|
||||
|
||||
func FillEntity(ctx *gin.Context, entity MediaFillable) error {
|
||||
videoIds := entity.GetVideoIds()
|
||||
videoMap, err := getVideoMapByIds(ctx, videoIds)
|
||||
|
|
|
@ -55,7 +55,7 @@ func transToCImage(image *dbstruct.Image) *dbstruct.ToCImage {
|
|||
W: image.W,
|
||||
H: image.H,
|
||||
Fmt: image.Fmt,
|
||||
Urls: []string{defaultMediaFiller.fileServerDomainName + imgSrcId},
|
||||
Urls: []string{defaultMediaFiller.GetFileServerDomain() + imgSrcId},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,14 +68,14 @@ func transToCVideo(video *dbstruct.Video, coverImg *dbstruct.Image) *dbstruct.To
|
|||
Id: video.Id,
|
||||
Dur: video.Dur,
|
||||
CoverUrls: []string{},
|
||||
Urls: []string{defaultMediaFiller.fileServerDomainName + video.SrcId},
|
||||
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.fileServerDomainName + imgSrcId}
|
||||
ret.CoverUrls = []string{defaultMediaFiller.GetFileServerDomain() + imgSrcId}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue