This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/answer-plugins.git
commit 49fbb36573e9074c2f1c8c57d4cbfd51ac9be269 Author: Luffy <5...@qq52o.cn> AuthorDate: Wed Apr 23 15:50:41 2025 +0800 feat(storage): support to set ACL_PUBLIC_READ ENV --- storage-aliyunoss/aliyunoss.go | 12 +++++++++++- storage-aliyunoss/info.yaml | 2 +- storage-tencentyuncos/info.yaml | 2 +- storage-tencentyuncos/tencentyuncos.go | 16 +++++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/storage-aliyunoss/aliyunoss.go b/storage-aliyunoss/aliyunoss.go index 153d177..4bb29e0 100644 --- a/storage-aliyunoss/aliyunoss.go +++ b/storage-aliyunoss/aliyunoss.go @@ -25,6 +25,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "os" "path/filepath" "strings" "time" @@ -40,6 +41,11 @@ import ( //go:embed info.yaml var Info embed.FS +var ( + // aclPublicRead is the environment variable for some special platforms such as digital ocean + aclPublicRead = os.Getenv("ACL_PUBLIC_READ") +) + type Storage struct { Config *StorageConfig } @@ -121,7 +127,11 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile ObjectKey: objectKey, Reader: open, } - respBody, err := bucket.DoPutObject(request, nil) + var options []oss.Option + if len(aclPublicRead) > 0 { + options = append(options, oss.ObjectACL(oss.ACLPublicRead)) + } + respBody, err := bucket.DoPutObject(request, options) if err != nil { resp.OriginalError = fmt.Errorf("upload file failed: %v", err) resp.DisplayErrorMsg = plugin.MakeTranslator(i18n.ErrUploadFileFailed) diff --git a/storage-aliyunoss/info.yaml b/storage-aliyunoss/info.yaml index cd95814..29a5109 100644 --- a/storage-aliyunoss/info.yaml +++ b/storage-aliyunoss/info.yaml @@ -17,6 +17,6 @@ slug_name: aliyunoss_storage type: storage -version: 1.2.12 +version: 1.2.13 author: answerdev link: https://github.com/apache/answer-plugins/tree/main/storage-aliyunoss diff --git a/storage-tencentyuncos/info.yaml b/storage-tencentyuncos/info.yaml index 47cc21c..8f97136 100644 --- a/storage-tencentyuncos/info.yaml +++ b/storage-tencentyuncos/info.yaml @@ -17,6 +17,6 @@ slug_name: tencentyuncos_storage type: storage -version: 1.0.3 +version: 1.0.4 author: Luffy link: https://github.com/apache/answer-plugins/tree/main/storage-tencentyuncos diff --git a/storage-tencentyuncos/tencentyuncos.go b/storage-tencentyuncos/tencentyuncos.go index ec46687..97a69b3 100644 --- a/storage-tencentyuncos/tencentyuncos.go +++ b/storage-tencentyuncos/tencentyuncos.go @@ -27,6 +27,7 @@ import ( "fmt" "net/http" "net/url" + "os" "path/filepath" "strings" "time" @@ -42,6 +43,11 @@ import ( //go:embed info.yaml var Info embed.FS +var ( + // aclPublicRead is the environment variable for some special platforms such as digital ocean + aclPublicRead = os.Getenv("ACL_PUBLIC_READ") +) + type Storage struct { Config *StorageConfig } @@ -122,7 +128,15 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile defer openFile.Close() objectKey := s.createObjectKey(file.Filename, condition.Source) - _, err = client.Object.Put(ctx, objectKey, openFile, nil) + var options *cos.ObjectPutOptions + if len(aclPublicRead) > 0 { + options = &cos.ObjectPutOptions{ + ACLHeaderOptions: &cos.ACLHeaderOptions{ + XCosACL: "public-read", + }, + } + } + _, err = client.Object.Put(ctx, objectKey, openFile, options) if err != nil { resp.OriginalError = fmt.Errorf("upload file failed: %v", err) resp.DisplayErrorMsg = plugin.MakeTranslator(i18n.ErrUploadFileFailed)