♻️ Refactor get s3 client process
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@ -31,11 +30,7 @@ func DownloadFileToLocal(meta models.Attachment, dst int) (string, error) {
|
||||
var destConfigured models.S3Destination
|
||||
_ = jsoniter.Unmarshal(rawDest, &destConfigured)
|
||||
|
||||
client, err := minio.New(destConfigured.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
|
||||
Secure: destConfigured.EnableSSL,
|
||||
BucketLookup: minio.BucketLookupType(destConfigured.BucketLookup),
|
||||
})
|
||||
client, err := destConfigured.GetClient()
|
||||
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to configure s3 client: %v", err)
|
||||
|
@ -7,14 +7,12 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
|
||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -121,12 +119,7 @@ func DeleteFileFromLocal(config models.LocalDestination, uuid string) error {
|
||||
}
|
||||
|
||||
func DeleteFileFromS3(config models.S3Destination, uuid string) error {
|
||||
client, err := minio.New(config.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.SecretID, config.SecretKey, ""),
|
||||
Secure: config.EnableSSL,
|
||||
BucketLookup: minio.BucketLookupType(config.BucketLookup),
|
||||
})
|
||||
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
|
||||
client, err := config.GetClient()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to configure s3 client: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user