feat: support send ali code

This commit is contained in:
2025-12-20 22:38:02 +08:00
parent 2382c72f57
commit 0221a21bc4
6 changed files with 317 additions and 25 deletions

View File

@@ -7,8 +7,29 @@ import (
"time"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func NewOSSClient(cfg *Config) (*OSSClient, error) {
cred := credentials.NewStaticCredentialsProvider(cfg.AccessKeyId, cfg.AccessKeySecret)
conf := oss.LoadDefaultConfig().
WithCredentialsProvider(cred).
WithRegion(cfg.Region).
WithUseCName(true).
WithEndpoint(*cfg.Host)
cfgInternal := oss.LoadDefaultConfig().
WithCredentialsProvider(cred).
WithRegion(cfg.Region)
return &OSSClient{
client: oss.NewClient(conf),
internalClient: oss.NewClient(cfgInternal),
config: cfg,
}, nil
}
type OSSOption func(*OSSOptions)
type OSSOptions struct {
@@ -42,7 +63,11 @@ func (c *OSSClient) GetClient() *oss.Client {
return c.client
}
func (c *OSSClient) PreSignUpload(ctx context.Context, path, mimeType string, opts ...OSSOption) (*oss.PresignResult, error) {
func (c *OSSClient) PreSignUpload(
ctx context.Context,
path, mimeType string,
opts ...OSSOption,
) (*oss.PresignResult, error) {
request := &oss.PutObjectRequest{
Bucket: oss.Ptr(c.config.Bucket),
Key: oss.Ptr(c.GetSavePath(path)),