mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-07 12:17:02 +08:00
feat: minio video snapshot
This commit is contained in:
parent
cb929e4c9c
commit
a643c2f89e
@ -126,13 +126,14 @@ api:
|
||||
# Configuration for Aliyun OSS
|
||||
object:
|
||||
enable: "minio"
|
||||
apiURL: http://127.0.0.1:10002/object/
|
||||
apiURL: http://127.0.0.1:10002
|
||||
minio:
|
||||
bucket: "openim"
|
||||
endpoint: http://127.0.0.1:10005
|
||||
accessKeyID: root
|
||||
secretAccessKey: openIM123
|
||||
sessionToken: ""
|
||||
thumbnailApi: "http://127.0.0.1:10003"
|
||||
cos:
|
||||
bucketURL: "https://temp-1252357374.cos.ap-chengdu.myqcloud.com"
|
||||
secretID: ""
|
||||
|
||||
@ -48,6 +48,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
if apiURL[len(apiURL)-1] != '/' {
|
||||
apiURL += "/"
|
||||
}
|
||||
apiURL += "object/"
|
||||
rdb, err := cache.NewRedis()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -119,6 +119,7 @@ type configStruct struct {
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
SecretAccessKey string `yaml:"secretAccessKey"`
|
||||
SessionToken string `yaml:"sessionToken"`
|
||||
ThumbnailApi string `yaml:"thumbnailApi"`
|
||||
} `yaml:"minio"`
|
||||
Cos struct {
|
||||
BucketURL string `yaml:"bucketURL"`
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/signer"
|
||||
@ -56,9 +57,17 @@ func NewMinio() (s3.Interface, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imageApi := conf.ThumbnailApi
|
||||
if imageApi != "" {
|
||||
if imageApi[len(imageApi)-1] != '/' {
|
||||
imageApi += "/"
|
||||
}
|
||||
imageApi += "image?"
|
||||
}
|
||||
m := &Minio{
|
||||
bucket: conf.Bucket,
|
||||
bucketURL: conf.Endpoint + "/" + conf.Bucket + "/",
|
||||
imageApi: imageApi,
|
||||
opts: opts,
|
||||
core: &minio.Core{Client: client},
|
||||
lock: &sync.Mutex{},
|
||||
@ -75,6 +84,7 @@ func NewMinio() (s3.Interface, error) {
|
||||
type Minio struct {
|
||||
bucket string
|
||||
bucketURL string
|
||||
imageApi string
|
||||
opts *minio.Options
|
||||
core *minio.Core
|
||||
lock sync.Locker
|
||||
@ -324,5 +334,20 @@ func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if opt.Image == nil && opt.Video == nil {
|
||||
return u.String(), nil
|
||||
}
|
||||
if m.imageApi == "" {
|
||||
return "", errs.ErrInternalServer.Wrap("minio: thumbnail not configured")
|
||||
}
|
||||
query := make(url.Values)
|
||||
query.Set("url", u.String())
|
||||
if opt.Image != nil {
|
||||
query.Set("type", "image")
|
||||
}
|
||||
if opt.Video != nil {
|
||||
query.Set("type", "video")
|
||||
query.Set("time", strconv.Itoa(int(opt.Video.Time/time.Millisecond)))
|
||||
}
|
||||
return m.imageApi + query.Encode(), nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user