Support pre-signed url

This commit is contained in:
LittleSheep 2024-12-28 23:16:07 +08:00
parent ec0444b35c
commit 90fb9960cc
2 changed files with 22 additions and 0 deletions

View File

@ -29,4 +29,5 @@ type S3Destination struct {
SecretKey string `json:"secret_key"` SecretKey string `json:"secret_key"`
AccessBaseURL string `json:"access_baseurl"` AccessBaseURL string `json:"access_baseurl"`
EnableSSL bool `json:"enable_ssl"` EnableSSL bool `json:"enable_ssl"`
EnabledSigned bool `json:"enabled_signed"`
} }

View File

@ -16,6 +16,8 @@ import (
"github.com/eko/gocache/lib/v4/marshaler" "github.com/eko/gocache/lib/v4/marshaler"
"github.com/eko/gocache/lib/v4/store" "github.com/eko/gocache/lib/v4/store"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/samber/lo" "github.com/samber/lo"
) )
@ -113,6 +115,25 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str
case models.DestinationTypeS3: case models.DestinationTypeS3:
var destConfigured models.S3Destination var destConfigured models.S3Destination
_ = jsoniter.Unmarshal(rawDest, &destConfigured) _ = jsoniter.Unmarshal(rawDest, &destConfigured)
if destConfigured.EnabledSigned {
var client *minio.Client
client, err = minio.New(destConfigured.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
Secure: destConfigured.EnableSSL,
})
if err != nil {
return
}
var uri *nurl.URL
uri, err = client.PresignedGetObject(context.Background(), destConfigured.Bucket, result.Attachment.Uuid, 60*time.Minute, nil)
if err != nil {
return
}
url = uri.String()
return
}
if len(destConfigured.AccessBaseURL) > 0 { if len(destConfigured.AccessBaseURL) > 0 {
url = fmt.Sprintf( url = fmt.Sprintf(
"%s/%s", "%s/%s",