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