优化结构

This commit is contained in:
Yvan
2026-08-24 13:25:16 +08:00
parent 7a9a738c6a
commit 0b6b8ddf1a
72 changed files with 2475 additions and 1443 deletions
+6 -6
View File
@@ -8,7 +8,7 @@ import (
"path"
"strings"
"kra/internal/conf"
"kra/internal/config"
"github.com/aws/aws-sdk-go-v2/aws"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
@@ -22,7 +22,7 @@ type awsStorage struct {
bucket, baseURL, prefix string
}
func newAWSStorage(provider string, config *conf.AdminBackend_ObjectStore) (system.FileStorage, error) {
func newAWSStorage(provider string, config *config.ObjectStore) (system.FileStorage, error) {
if config == nil || config.Bucket == "" || config.AccessKey == "" || config.SecretKey == "" {
return nil, fmt.Errorf("%s storage configuration is incomplete", provider)
}
@@ -31,10 +31,10 @@ func newAWSStorage(provider string, config *conf.AdminBackend_ObjectStore) (syst
if provider == "cloudflare-r2" {
region = "auto"
if endpoint == "" {
if config.AccountId == "" {
if config.AccountID == "" {
return nil, fmt.Errorf("cloudflare-r2 account id is required")
}
endpoint = fmt.Sprintf("https://%s.r2.cloudflarestorage.com", config.AccountId)
endpoint = fmt.Sprintf("https://%s.r2.cloudflarestorage.com", config.AccountID)
}
}
if region == "" {
@@ -47,7 +47,7 @@ func newAWSStorage(provider string, config *conf.AdminBackend_ObjectStore) (syst
client := s3.NewFromConfig(loaded, func(options *s3.Options) {
if endpoint != "" {
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
if config.UseSsl {
if config.UseSSL {
endpoint = "https://" + endpoint
} else {
endpoint = "http://" + endpoint
@@ -57,7 +57,7 @@ func newAWSStorage(provider string, config *conf.AdminBackend_ObjectStore) (syst
}
options.UsePathStyle = config.ForcePathStyle
})
return &awsStorage{client: client, bucket: config.Bucket, baseURL: strings.TrimSuffix(config.BaseUrl, "/"), prefix: strings.Trim(config.PathPrefix, "/")}, nil
return &awsStorage{client: client, bucket: config.Bucket, baseURL: strings.TrimSuffix(config.BaseURL, "/"), prefix: strings.Trim(config.PathPrefix, "/")}, nil
}
func (s *awsStorage) key(name string) string {