mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-14 05:56:00 +08:00
feat: add scripts (#525)
This commit is contained in:
@@ -4,16 +4,18 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/signer"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/signer"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -79,7 +81,12 @@ func (m *Minio) InitiateMultipartUpload(ctx context.Context, name string) (*s3.I
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *Minio) CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []s3.Part) (*s3.CompleteMultipartUploadResult, error) {
|
||||
func (m *Minio) CompleteMultipartUpload(
|
||||
ctx context.Context,
|
||||
uploadID string,
|
||||
name string,
|
||||
parts []s3.Part,
|
||||
) (*s3.CompleteMultipartUploadResult, error) {
|
||||
minioParts := make([]minio.CompletePart, len(parts))
|
||||
for i, part := range parts {
|
||||
minioParts[i] = minio.CompletePart{
|
||||
@@ -116,7 +123,13 @@ func (m *Minio) PartSize(ctx context.Context, size int64) (int64, error) {
|
||||
return partSize, nil
|
||||
}
|
||||
|
||||
func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*s3.AuthSignResult, error) {
|
||||
func (m *Minio) AuthSign(
|
||||
ctx context.Context,
|
||||
uploadID string,
|
||||
name string,
|
||||
expire time.Duration,
|
||||
partNumbers []int,
|
||||
) (*s3.AuthSignResult, error) {
|
||||
creds, err := m.opts.Creds.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -133,7 +146,14 @@ func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expi
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Set("X-Amz-Content-Sha256", unsignedPayload)
|
||||
request = signer.SignV4Trailer(*request, creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, "us-east-1", nil)
|
||||
request = signer.SignV4Trailer(
|
||||
*request,
|
||||
creds.AccessKeyID,
|
||||
creds.SecretAccessKey,
|
||||
creds.SessionToken,
|
||||
"us-east-1",
|
||||
nil,
|
||||
)
|
||||
result.Parts[i] = s3.SignPart{
|
||||
PartNumber: partNumber,
|
||||
URL: request.URL.String(),
|
||||
@@ -204,7 +224,13 @@ func (m *Minio) AbortMultipartUpload(ctx context.Context, uploadID string, name
|
||||
return m.core.AbortMultipartUpload(ctx, m.bucket, name, uploadID)
|
||||
}
|
||||
|
||||
func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*s3.ListUploadedPartsResult, error) {
|
||||
func (m *Minio) ListUploadedParts(
|
||||
ctx context.Context,
|
||||
uploadID string,
|
||||
name string,
|
||||
partNumberMarker int,
|
||||
maxParts int,
|
||||
) (*s3.ListUploadedPartsResult, error) {
|
||||
result, err := m.core.ListObjectParts(ctx, m.bucket, name, uploadID, partNumberMarker, maxParts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -227,7 +253,12 @@ func (m *Minio) ListUploadedParts(ctx context.Context, uploadID string, name str
|
||||
return res, nil
|
||||
}
|
||||
|
||||
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)
|
||||
//if opt != nil {
|
||||
// if opt.ContentType != "" {
|
||||
|
||||
Reference in New Issue
Block a user