mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-07 12:17:02 +08:00
feat: cos video snapshot
This commit is contained in:
parent
6c72578171
commit
89c18ac358
@ -263,7 +263,7 @@ func (c *Cos) ListUploadedParts(ctx context.Context, uploadID string, name strin
|
|||||||
|
|
||||||
func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
||||||
var imageMogr string
|
var imageMogr string
|
||||||
snapshot := make(url.Values)
|
//snapshot := make(url.Values)
|
||||||
var option *cos.PresignedURLOptions
|
var option *cos.PresignedURLOptions
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
query := make(url.Values)
|
query := make(url.Values)
|
||||||
@ -300,8 +300,14 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if opt.Video != nil {
|
if opt.Video != nil {
|
||||||
snapshot.Set("ci-process", "snapshot")
|
// 对象存储/桶存储列表/数据处理/媒体处理 开启
|
||||||
snapshot.Set("time", strconv.FormatFloat(float64(opt.Video.Time/time.Millisecond)/1000, 'f', 3, 64))
|
// https://cloud.tencent.com/document/product/436/55671
|
||||||
|
query.Set("ci-process", "snapshot")
|
||||||
|
sec := float64(opt.Video.Time/time.Millisecond) / 1000
|
||||||
|
if sec < 0 {
|
||||||
|
sec = 0
|
||||||
|
}
|
||||||
|
query.Set("time", strconv.FormatFloat(sec, 'f', 3, 64))
|
||||||
switch opt.Video.ImageFormat {
|
switch opt.Video.ImageFormat {
|
||||||
case
|
case
|
||||||
videoSnapshotImagePng,
|
videoSnapshotImagePng,
|
||||||
@ -309,13 +315,19 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
default:
|
default:
|
||||||
opt.Video.ImageFormat = videoSnapshotImageJpg
|
opt.Video.ImageFormat = videoSnapshotImageJpg
|
||||||
}
|
}
|
||||||
snapshot.Set("format", opt.Video.ImageFormat)
|
query.Set("format", opt.Video.ImageFormat)
|
||||||
opt.ContentType = "image/" + opt.Video.ImageFormat
|
opt.ContentType = "image/" + opt.Video.ImageFormat
|
||||||
if opt.Filename == "" {
|
if opt.Filename == "" {
|
||||||
opt.Filename = filepath.Base(name) + "." + opt.Video.ImageFormat
|
opt.Filename = filepath.Base(name) + "." + opt.Video.ImageFormat
|
||||||
} else if filepath.Ext(opt.Filename) != "."+opt.Video.ImageFormat {
|
} else if filepath.Ext(opt.Filename) != "."+opt.Video.ImageFormat {
|
||||||
opt.Filename += "." + opt.Video.ImageFormat
|
opt.Filename += "." + opt.Video.ImageFormat
|
||||||
}
|
}
|
||||||
|
if opt.Video.Width > 0 {
|
||||||
|
query.Set("width", strconv.Itoa(opt.Video.Width))
|
||||||
|
}
|
||||||
|
if opt.Video.Height > 0 {
|
||||||
|
query.Set("height", strconv.Itoa(opt.Video.Height))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if opt.ContentType != "" {
|
if opt.ContentType != "" {
|
||||||
query.Set("response-content-type", opt.ContentType)
|
query.Set("response-content-type", opt.ContentType)
|
||||||
@ -339,17 +351,6 @@ func (c *Cos) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
urlStr := rawURL.String()
|
urlStr := rawURL.String()
|
||||||
if len(snapshot) > 0 {
|
|
||||||
r, err := url.Parse(urlStr)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
query := r.Query()
|
|
||||||
for key, values := range snapshot {
|
|
||||||
query[key] = values
|
|
||||||
}
|
|
||||||
r.RawQuery = query.Encode()
|
|
||||||
}
|
|
||||||
if imageMogr != "" {
|
if imageMogr != "" {
|
||||||
urlStr += imageMogr
|
urlStr += imageMogr
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user