mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-11 23:47:32 +08:00
s3 public read
This commit is contained in:
parent
52796bf79d
commit
e8d7e3861d
@ -18,14 +18,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/tencentyun/cos-go-sdk-v5"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tencentyun/cos-go-sdk-v5"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -275,6 +275,7 @@ func (o *OSS) ListUploadedParts(ctx context.Context, uploadID string, name strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
||||||
|
publicRead := config.Config.Object.Oss.PublicRead
|
||||||
var opts []oss.Option
|
var opts []oss.Option
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
if opt.Image != nil {
|
if opt.Image != nil {
|
||||||
@ -302,11 +303,13 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
process += ",format," + format
|
process += ",format," + format
|
||||||
opts = append(opts, oss.Process(process))
|
opts = append(opts, oss.Process(process))
|
||||||
}
|
}
|
||||||
if opt.ContentType != "" {
|
if !publicRead {
|
||||||
opts = append(opts, oss.ResponseContentType(opt.ContentType))
|
if opt.ContentType != "" {
|
||||||
}
|
opts = append(opts, oss.ResponseContentType(opt.ContentType))
|
||||||
if opt.Filename != "" {
|
}
|
||||||
opts = append(opts, oss.ResponseContentDisposition(`attachment; filename=`+strconv.Quote(opt.Filename)))
|
if opt.Filename != "" {
|
||||||
|
opts = append(opts, oss.ResponseContentDisposition(`attachment; filename=`+strconv.Quote(opt.Filename)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if expire <= 0 {
|
if expire <= 0 {
|
||||||
@ -314,15 +317,13 @@ func (o *OSS) AccessURL(ctx context.Context, name string, expire time.Duration,
|
|||||||
} else if expire < time.Second {
|
} else if expire < time.Second {
|
||||||
expire = time.Second
|
expire = time.Second
|
||||||
}
|
}
|
||||||
if !config.Config.Object.Oss.PublicRead {
|
if !publicRead {
|
||||||
return o.bucket.SignURL(name, http.MethodGet, int64(expire/time.Second), opts...)
|
return o.bucket.SignURL(name, http.MethodGet, int64(expire/time.Second), opts...)
|
||||||
}
|
}
|
||||||
rawParams, err := oss.GetRawParams(opts)
|
rawParams, err := oss.GetRawParams(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
l := len(rawParams)
|
|
||||||
_ = l
|
|
||||||
params := getURLParams(*o.bucket.Client.Conn, rawParams)
|
params := getURLParams(*o.bucket.Client.Conn, rawParams)
|
||||||
return getURL(o.um, o.bucket.BucketName, name, params).String(), nil
|
return getURL(o.um, o.bucket.BucketName, name, params).String(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user