♻️ refactored thumbnail storage strategy
This commit is contained in:
@@ -2,9 +2,9 @@ package initialize
|
||||
|
||||
import (
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wenlng/go-captcha-assets/bindata/chars"
|
||||
"github.com/wenlng/go-captcha-assets/resources/fonts/fzshengsksjw"
|
||||
"github.com/wenlng/go-captcha-assets/resources/images"
|
||||
"github.com/wenlng/go-captcha-assets/sourcedata/chars"
|
||||
"github.com/wenlng/go-captcha/v2/base/option"
|
||||
"github.com/wenlng/go-captcha/v2/click"
|
||||
)
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
FaceBucketName = "schisandra-face-samples"
|
||||
CommentImagesBucketName = "schisandra-comment-images"
|
||||
ThumbnailBucketName = "schisandra-thumbnail-images"
|
||||
ShareThumbnailBucketName = "schisandra-share-thumbnails"
|
||||
FaceBucketName = "schisandra-face-samples"
|
||||
CommentImagesBucketName = "schisandra-comment-images"
|
||||
ThumbnailBucketName = "schisandra-thumbnail-images"
|
||||
ShareImagesBucketName = "schisandra-share-images"
|
||||
)
|
||||
|
6
common/constant/storage_space_name.go
Normal file
6
common/constant/storage_space_name.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
ImageSpace = "image_space"
|
||||
ThumbnailSpace = "thumbnail_space"
|
||||
)
|
@@ -1,8 +1,11 @@
|
||||
package miniox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
)
|
||||
|
||||
func NewMinio(endpoint, accessKeyID, secretAccessKey string, useSSL bool) *minio.Client {
|
||||
@@ -13,5 +16,38 @@ func NewMinio(endpoint, accessKeyID, secretAccessKey string, useSSL bool) *minio
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// 初始化存储桶
|
||||
thumbnailBucketExists, err := client.BucketExists(context.Background(), constant.ThumbnailBucketName)
|
||||
if err != nil || !thumbnailBucketExists {
|
||||
err = client.MakeBucket(context.Background(), constant.ThumbnailBucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
|
||||
if err != nil {
|
||||
logx.Errorf("Failed to create MinIO bucket: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
faceBucketExists, err := client.BucketExists(context.Background(), constant.FaceBucketName)
|
||||
if err != nil || !faceBucketExists {
|
||||
err = client.MakeBucket(context.Background(), constant.FaceBucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
|
||||
if err != nil {
|
||||
logx.Errorf("Failed to create MinIO bucket: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
commentImagesBucketExists, err := client.BucketExists(context.Background(), constant.CommentImagesBucketName)
|
||||
if err != nil || !commentImagesBucketExists {
|
||||
err = client.MakeBucket(context.Background(), constant.CommentImagesBucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
|
||||
if err != nil {
|
||||
logx.Errorf("Failed to create MinIO bucket: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
shareImagesBucketExists, err := client.BucketExists(context.Background(), constant.ShareImagesBucketName)
|
||||
if err != nil || !shareImagesBucketExists {
|
||||
err = client.MakeBucket(context.Background(), constant.ShareImagesBucketName, minio.MakeBucketOptions{Region: "us-east-1", ObjectLocking: true})
|
||||
if err != nil {
|
||||
logx.Errorf("Failed to create MinIO bucket: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
Reference in New Issue
Block a user