mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge branch 'v3dev' of github.com:OpenIMSDK/Open-IM-Server into v3dev
This commit is contained in:
commit
38912aed76
@ -34,7 +34,7 @@ func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.In
|
|||||||
if err := checkUploadName(ctx, req.Name); err != nil {
|
if err := checkUploadName(ctx, req.Name); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result, err := t.s3dataBase.InitiateMultipartUpload(ctx, req.Hash, req.Size, time.Hour*24, int(req.MaxParts))
|
result, err := t.s3dataBase.InitiateMultipartUpload(ctx, req.Hash, req.Size, time.Hour*24*7, int(req.MaxParts))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if haErr, ok := errs.Unwrap(err).(*cont.HashAlreadyExistsError); ok {
|
if haErr, ok := errs.Unwrap(err).(*cont.HashAlreadyExistsError); ok {
|
||||||
obj := &relation.ObjectModel{
|
obj := &relation.ObjectModel{
|
||||||
@ -51,7 +51,7 @@ func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.In
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &third.InitiateMultipartUploadResp{
|
return &third.InitiateMultipartUploadResp{
|
||||||
Url: t.apiAddress(obj.Key),
|
Url: t.apiAddress(obj.Name),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -77,7 +77,7 @@ func (c *Cos) CompleteMultipartUpload(ctx context.Context, uploadID string, name
|
|||||||
for i, part := range parts {
|
for i, part := range parts {
|
||||||
opts.Parts[i] = cos.Object{
|
opts.Parts[i] = cos.Object{
|
||||||
PartNumber: part.PartNumber,
|
PartNumber: part.PartNumber,
|
||||||
ETag: strings.ToLower(part.ETag),
|
ETag: strings.ReplaceAll(part.ETag, `"`, ``),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, _, err := c.client.Object.CompleteMultipartUpload(ctx, name, uploadID, opts)
|
result, _, err := c.client.Object.CompleteMultipartUpload(ctx, name, uploadID, opts)
|
||||||
@ -109,27 +109,6 @@ func (c *Cos) PartSize(ctx context.Context, size int64) (int64, error) {
|
|||||||
return partSize, nil
|
return partSize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cos) ClientUploadPart(ctx context.Context, partSize int64, expire time.Duration, upload *s3.InitiateMultipartUploadResult) (*s3.MultipartUploadRequest, error) {
|
|
||||||
uri := c.client.BaseURL.BucketURL.String() + "/" + cos.EncodeURIComponent(upload.Key)
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, uri, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
cos.AddAuthorizationHeader(c.credential.SecretID, c.credential.SecretKey, c.credential.SessionToken, req, cos.NewAuthTime(expire))
|
|
||||||
return &s3.MultipartUploadRequest{
|
|
||||||
UploadID: upload.UploadID,
|
|
||||||
Bucket: upload.Bucket,
|
|
||||||
Key: upload.Key,
|
|
||||||
Method: req.Method,
|
|
||||||
URL: uri,
|
|
||||||
Query: url.Values{"uploadId": {upload.UploadID}},
|
|
||||||
Header: req.Header,
|
|
||||||
PartKey: "partNumber",
|
|
||||||
PartSize: partSize,
|
|
||||||
FirstPart: 1,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Cos) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) {
|
func (c *Cos) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) {
|
||||||
result := s3.AuthSignResult{
|
result := s3.AuthSignResult{
|
||||||
URL: c.client.BaseURL.BucketURL.String() + "/" + cos.EncodeURIComponent(name),
|
URL: c.client.BaseURL.BucketURL.String() + "/" + cos.EncodeURIComponent(name),
|
||||||
@ -200,13 +179,14 @@ func (c *Cos) StatObject(ctx context.Context, name string) (*s3.ObjectInfo, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cos) CopyObject(ctx context.Context, src string, dst string) (*s3.CopyObjectInfo, error) {
|
func (c *Cos) CopyObject(ctx context.Context, src string, dst string) (*s3.CopyObjectInfo, error) {
|
||||||
result, _, err := c.client.Object.Copy(ctx, dst, c.copyURL+src, &cos.ObjectCopyOptions{})
|
sourceURL := c.copyURL + src
|
||||||
|
result, _, err := c.client.Object.Copy(ctx, dst, sourceURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &s3.CopyObjectInfo{
|
return &s3.CopyObjectInfo{
|
||||||
Key: dst,
|
Key: dst,
|
||||||
ETag: result.ETag,
|
ETag: strings.ReplaceAll(result.ETag, `"`, ``),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,21 +232,21 @@ 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) {
|
||||||
reqParams := make(url.Values)
|
//reqParams := make(url.Values)
|
||||||
if opt != nil {
|
//if opt != nil {
|
||||||
if opt.ContentType != "" {
|
// if opt.ContentType != "" {
|
||||||
reqParams.Set("Content-Type", opt.ContentType)
|
// reqParams.Set("Content-Type", opt.ContentType)
|
||||||
}
|
// }
|
||||||
if opt.ContentDisposition != "" {
|
// if opt.ContentDisposition != "" {
|
||||||
reqParams.Set("Content-Disposition", opt.ContentDisposition)
|
// reqParams.Set("Content-Disposition", opt.ContentDisposition)
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
if expire <= 0 {
|
if expire <= 0 {
|
||||||
expire = time.Hour * 24 * 365 * 99 // 99 years
|
expire = time.Hour * 24 * 365 * 99 // 99 years
|
||||||
} else if expire < time.Second {
|
} else if expire < time.Second {
|
||||||
expire = time.Second
|
expire = time.Second
|
||||||
}
|
}
|
||||||
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, reqParams)
|
rawURL, err := c.client.Object.GetPresignedURL(ctx, http.MethodGet, name, c.credential.SecretID, c.credential.SecretKey, expire, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -228,21 +228,21 @@ func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
func (m *Minio) AccessURL(ctx context.Context, name string, expire time.Duration, opt *s3.AccessURLOption) (string, error) {
|
||||||
reqParams := make(url.Values)
|
//reqParams := make(url.Values)
|
||||||
if opt != nil {
|
//if opt != nil {
|
||||||
if opt.ContentType != "" {
|
// if opt.ContentType != "" {
|
||||||
reqParams.Set("Content-Type", opt.ContentType)
|
// reqParams.Set("Content-Type", opt.ContentType)
|
||||||
}
|
// }
|
||||||
if opt.ContentDisposition != "" {
|
// if opt.ContentDisposition != "" {
|
||||||
reqParams.Set("Content-Disposition", opt.ContentDisposition)
|
// reqParams.Set("Content-Disposition", opt.ContentDisposition)
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
if expire <= 0 {
|
if expire <= 0 {
|
||||||
expire = time.Hour * 24 * 365 * 99 // 99 years
|
expire = time.Hour * 24 * 365 * 99 // 99 years
|
||||||
} else if expire < time.Second {
|
} else if expire < time.Second {
|
||||||
expire = time.Second
|
expire = time.Second
|
||||||
}
|
}
|
||||||
u, err := m.core.Client.PresignedGetObject(ctx, m.bucket, name, expire, reqParams)
|
u, err := m.core.Client.PresignedGetObject(ctx, m.bucket, name, expire, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -241,19 +241,19 @@ 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) {
|
||||||
var opts []oss.Option
|
//var opts []oss.Option
|
||||||
if opt != nil {
|
//if opt != nil {
|
||||||
if opt.ContentType != "" {
|
// if opt.ContentType != "" {
|
||||||
opts = append(opts, oss.ContentType(opt.ContentType))
|
// opts = append(opts, oss.ContentType(opt.ContentType))
|
||||||
}
|
// }
|
||||||
if opt.ContentDisposition != "" {
|
// if opt.ContentDisposition != "" {
|
||||||
opts = append(opts, oss.ContentDisposition(opt.ContentDisposition))
|
// opts = append(opts, oss.ContentDisposition(opt.ContentDisposition))
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
if expire <= 0 {
|
if expire <= 0 {
|
||||||
expire = time.Hour * 24 * 365 * 99 // 99 years
|
expire = time.Hour * 24 * 365 * 99 // 99 years
|
||||||
} else if expire < time.Second {
|
} else if expire < time.Second {
|
||||||
expire = time.Second
|
expire = time.Second
|
||||||
}
|
}
|
||||||
return o.bucket.SignURL(name, http.MethodGet, int64(expire/time.Second), opts...)
|
return o.bucket.SignURL(name, http.MethodGet, int64(expire/time.Second))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user