pls fucking work
This commit is contained in:
@@ -52,7 +52,6 @@ func main() {
|
|||||||
Bucket: cfg.StorageBucket,
|
Bucket: cfg.StorageBucket,
|
||||||
UseSSL: cfg.StorageUseSSL,
|
UseSSL: cfg.StorageUseSSL,
|
||||||
PublicUseSSL: true,
|
PublicUseSSL: true,
|
||||||
CORSOrigins: cfg.CORSOrigin,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("storage unavailable: %v", err)
|
log.Fatalf("storage unavailable: %v", err)
|
||||||
|
|||||||
@@ -4,11 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/minio/minio-go/v7/pkg/cors"
|
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +18,6 @@ type Config struct {
|
|||||||
Bucket string
|
Bucket string
|
||||||
UseSSL bool
|
UseSSL bool
|
||||||
PublicUseSSL bool
|
PublicUseSSL bool
|
||||||
CORSOrigins string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectInfo struct {
|
type ObjectInfo struct {
|
||||||
@@ -44,7 +41,6 @@ type MinIO struct {
|
|||||||
client *minio.Client
|
client *minio.Client
|
||||||
publicClient *minio.Client
|
publicClient *minio.Client
|
||||||
bucket string
|
bucket string
|
||||||
corsOrigins string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMinIO(config Config) (*MinIO, error) {
|
func NewMinIO(config Config) (*MinIO, error) {
|
||||||
@@ -74,7 +70,6 @@ func NewMinIO(config Config) (*MinIO, error) {
|
|||||||
client: client,
|
client: client,
|
||||||
publicClient: publicClient,
|
publicClient: publicClient,
|
||||||
bucket: config.Bucket,
|
bucket: config.Bucket,
|
||||||
corsOrigins: config.CORSOrigins,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,32 +86,6 @@ func (s *MinIO) EnsureBucket(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
origins := make([]string, 0)
|
|
||||||
for _, origin := range strings.Split(s.corsOrigins, ",") {
|
|
||||||
if value := strings.TrimSpace(origin); value != "" {
|
|
||||||
origins = append(origins, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(origins) == 0 {
|
|
||||||
origins = []string{"*"}
|
|
||||||
}
|
|
||||||
if err := s.client.SetBucketCors(ctx, s.bucket, cors.NewConfig([]cors.Rule{{
|
|
||||||
ID: "studio-browser-uploads",
|
|
||||||
AllowedOrigin: origins,
|
|
||||||
AllowedMethod: []string{"GET", "PUT", "POST", "DELETE", "HEAD"},
|
|
||||||
AllowedHeader: []string{
|
|
||||||
"Content-Type",
|
|
||||||
"x-amz-acl",
|
|
||||||
"x-amz-date",
|
|
||||||
"x-amz-content-sha256",
|
|
||||||
"Authorization",
|
|
||||||
"Origin",
|
|
||||||
},
|
|
||||||
ExposeHeader: []string{"ETag", "x-amz-request-id", "x-amz-id-2"},
|
|
||||||
MaxAgeSeconds: 3600,
|
|
||||||
}})); err != nil {
|
|
||||||
return fmt.Errorf("configure object storage CORS: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user