Auto to set bucket lookup method

This commit is contained in:
LittleSheep 2025-03-24 22:46:23 +08:00
parent 1a1b9eb556
commit 9360d17706
5 changed files with 21 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models" "git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
@ -31,9 +32,11 @@ func DownloadFileToLocal(meta models.Attachment, dst int) (string, error) {
_ = jsoniter.Unmarshal(rawDest, &destConfigured) _ = jsoniter.Unmarshal(rawDest, &destConfigured)
client, err := minio.New(destConfigured.Endpoint, &minio.Options{ client, err := minio.New(destConfigured.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""), Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
Secure: destConfigured.EnableSSL, Secure: destConfigured.EnableSSL,
BucketLookup: minio.BucketLookupType(destConfigured.BucketLookup),
}) })
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
if err != nil { if err != nil {
return "", fmt.Errorf("unable to configure s3 client: %v", err) return "", fmt.Errorf("unable to configure s3 client: %v", err)
} }

View File

@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"github.com/samber/lo" "github.com/samber/lo"
@ -121,9 +122,11 @@ func DeleteFileFromLocal(config models.LocalDestination, uuid string) error {
func DeleteFileFromS3(config models.S3Destination, uuid string) error { func DeleteFileFromS3(config models.S3Destination, uuid string) error {
client, err := minio.New(config.Endpoint, &minio.Options{ client, err := minio.New(config.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(config.SecretID, config.SecretKey, ""), Creds: credentials.NewStaticV4(config.SecretID, config.SecretKey, ""),
Secure: config.EnableSSL, Secure: config.EnableSSL,
BucketLookup: minio.BucketLookupType(config.BucketLookup),
}) })
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
if err != nil { if err != nil {
return fmt.Errorf("unable to configure s3 client: %v", err) return fmt.Errorf("unable to configure s3 client: %v", err)
} }

View File

@ -31,4 +31,5 @@ type S3Destination struct {
AccessBaseURL string `json:"access_baseurl"` AccessBaseURL string `json:"access_baseurl"`
EnableSSL bool `json:"enable_ssl"` EnableSSL bool `json:"enable_ssl"`
EnableSigned bool `json:"enable_signed"` EnableSigned bool `json:"enable_signed"`
BucketLookup int `json:"bucket_lookup"`
} }

View File

@ -9,6 +9,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
localCache "git.solsynth.dev/hypernet/paperclip/pkg/internal/cache" localCache "git.solsynth.dev/hypernet/paperclip/pkg/internal/cache"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models" "git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@ -118,9 +119,11 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str
if destConfigured.EnableSigned { if destConfigured.EnableSigned {
var client *minio.Client var client *minio.Client
client, err = minio.New(destConfigured.Endpoint, &minio.Options{ client, err = minio.New(destConfigured.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""), Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
Secure: destConfigured.EnableSSL, Secure: destConfigured.EnableSSL,
BucketLookup: minio.BucketLookupType(destConfigured.BucketLookup),
}) })
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
if err != nil { if err != nil {
return return
} }

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
pkg "git.solsynth.dev/hypernet/paperclip/pkg/internal"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/fs" "git.solsynth.dev/hypernet/paperclip/pkg/internal/fs"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models" "git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@ -92,9 +93,11 @@ func ReUploadFile(meta models.Attachment, dst int, doNotUpdate ...bool) error {
_ = jsoniter.Unmarshal(rawDest, &destConfigured) _ = jsoniter.Unmarshal(rawDest, &destConfigured)
client, err := minio.New(destConfigured.Endpoint, &minio.Options{ client, err := minio.New(destConfigured.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""), Creds: credentials.NewStaticV4(destConfigured.SecretID, destConfigured.SecretKey, ""),
Secure: destConfigured.EnableSSL, Secure: destConfigured.EnableSSL,
BucketLookup: minio.BucketLookupType(destConfigured.BucketLookup),
}) })
client.SetAppInfo("HyperNet.Paperclip", pkg.AppVersion)
if err != nil { if err != nil {
return fmt.Errorf("unable to configure s3 client: %v", err) return fmt.Errorf("unable to configure s3 client: %v", err)
} }