瀏覽代碼

修复头像

kobe6258 3 月之前
父節點
當前提交
800645c103
共有 3 個文件被更改,包括 2 次插入130 次删除
  1. 1 3
      main.go
  2. 1 2
      utils/config.go
  3. 0 125
      utils/minio.go

+ 1 - 3
main.go

@@ -25,9 +25,7 @@ func main() {
 	web.BConfig.MaxMemory = 1024 * 1024 * 128
 	web.BConfig.RecoverFunc = Recover
 
-	if utils.MinioClient != nil {
-		services.RepairImageData()
-	}
+	services.RepairImageData()
 	web.Run()
 }
 

+ 1 - 2
utils/config.go

@@ -15,7 +15,6 @@ var (
 	REDIS_CACHE string      //缓存地址
 	Rc          RedisClient //redis缓存
 	PRCPool     ClientPool  //rpc连接池
-	MinioClient *MinioOss
 )
 var ObjectStorageClient string // 目前有oss minio,默认oss
 // 推送模版消息
@@ -256,5 +255,5 @@ func init() {
 
 	Rc = redisClient
 
-	MinioClient = DefaultClient()
+	//MinioClient = DefaultClient()
 }

+ 0 - 125
utils/minio.go

@@ -1,125 +0,0 @@
-package utils
-
-import (
-	"context"
-	"github.com/minio/minio-go/v7"
-	"github.com/minio/minio-go/v7/pkg/credentials"
-	"sync"
-	"time"
-)
-
-const (
-	DefaultExpiredTime = 30 * time.Minute
-)
-
-var (
-	once        sync.Once
-	minioClient *MinioOss
-)
-
-type MinioOss struct {
-	bucketName  string
-	ObjectName  string
-	minioClient *minio.Client
-	ExpiredTime time.Duration
-}
-
-func (mo *MinioOss) oss() *minio.Client {
-	return mo.minioClient
-}
-func (mo *MinioOss) GetObject(objectName string, filePath string) (err error) {
-	err = minioClient.oss().FGetObject(context.Background(), mo.GetBucketName(), objectName, filePath, minio.GetObjectOptions{})
-	return
-}
-func (mo *MinioOss) SaveObject(objectName string, filePath string) (err error) {
-	_, err = minioClient.oss().FPutObject(context.Background(), mo.GetBucketName(), objectName, filePath, minio.PutObjectOptions{})
-	return
-}
-func (mo *MinioOss) GetState(objectName string) (state minio.ObjectInfo, err error) {
-	state, err = minioClient.oss().StatObject(context.Background(), mo.GetBucketName(), objectName, minio.GetObjectOptions{})
-	return
-}
-func (mo *MinioOss) GetObjectExt(contentType string) (ext string) {
-	return getFileExtensionFromContentType(contentType)
-}
-func getFileExtensionFromContentType(contentType string) string {
-	switch contentType {
-	case "image/jpeg":
-		return ".jpg"
-	case "image/png":
-		return ".png"
-	case "application/pdf":
-		return ".pdf"
-	case "application/msword":
-		return ".doc"
-	case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
-		return ".docx"
-	case "application/vnd.ms-excel":
-		return ".xls"
-	case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
-		return ".xlsx"
-	case "text/plain":
-		return ".txt"
-	case "application/json":
-		return ".json"
-	case "application/octet-stream":
-		return ".bin"
-	default:
-		return ""
-	}
-}
-
-func DefaultClient() *MinioOss {
-	once.Do(func() {
-		if minioClient == nil {
-			// 此处兼容一下前后端endpoint不一致的情况, 前端用minio_endpoint后端用minio_back_endpoint, minio_back_endpoint为空则都取前者
-			endpoint := MinIoEndpoint
-			if MinIoBackEndpoint != "" {
-				endpoint = MinIoBackEndpoint
-			}
-			accessKeyID := MinIoAccessKeyId
-			secretAccessKey := MinIoAccessKeySecret
-			useSSL := false
-			if MinIoUseSSL == "true" {
-				useSSL = true
-			}
-			client, err := minio.New(endpoint, &minio.Options{
-				Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
-				Secure: useSSL,
-			})
-			if err != nil {
-				FileLog.Error("初始化minio客户端失败: %s", err)
-			}
-			bucketName := MinIoBucketname
-			exists, errBucketExists := client.BucketExists(context.Background(), bucketName)
-			if errBucketExists != nil || !exists {
-				FileLog.Error("BucketExists: %v; err: %v", exists, errBucketExists)
-			}
-			minioClient = &MinioOss{
-				minioClient: client,
-				bucketName:  bucketName,
-				ExpiredTime: DefaultExpiredTime,
-			}
-		}
-	})
-	return minioClient
-}
-
-func (mo *MinioOss) GetBucketName() string {
-	return mo.bucketName
-}
-func (mo *MinioOss) GetExpiredTime() time.Duration {
-	return mo.ExpiredTime
-}
-
-// 生成预签名的PUT URL
-func (mo *MinioOss) GeneratePreSignedPutURLHandler(objectName string) (url string, err error) {
-	// 生成预签名的PUT URL
-	PreSignedURL, err := minioClient.oss().PresignedPutObject(context.Background(), minioClient.GetBucketName(), objectName, minioClient.GetExpiredTime())
-	if err != nil {
-		FileLog.Error("生成预签名的PUT URL失败: %s", err)
-		return
-	}
-	url = PreSignedURL.String()
-	return
-}