add transaction picture upload api

This commit is contained in:
MaysWind
2024-08-30 00:33:48 +08:00
parent fe442f27f2
commit 73c69c3761
18 changed files with 462 additions and 10 deletions
+4
View File
@@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"net/http"
"strings"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
@@ -40,6 +41,7 @@ func NewMinIOObjectStorage(config *settings.Config, pathPrefix string) (*MinIOOb
}
storage.rootPath = storage.getFinalPath(pathPrefix)
storage.rootPath = strings.ReplaceAll(storage.rootPath, "\\", "/")
ctx := context.Background()
exists, err := minIOClient.BucketExists(ctx, minIOConfig.Bucket)
@@ -104,5 +106,7 @@ func (s *MinIOObjectStorage) getFinalPath(path string) string {
path = path[1:]
}
path = strings.ReplaceAll(path, "\\", "/")
return rootPath + path
}
+46 -10
View File
@@ -6,10 +6,12 @@ import (
)
const avatarPathPrefix = "avatar"
const transactionPicturePathPrefix = "transaction"
// StorageContainer contains the current object storage
type StorageContainer struct {
AvatarCurrentStorage ObjectStorage
AvatarCurrentStorage ObjectStorage
TransactionPictureCurrentStorage ObjectStorage
}
// Initialize a object storage container singleton instance
@@ -19,19 +21,23 @@ var (
// InitializeStorageContainer initializes the current object storage according to the config
func InitializeStorageContainer(config *settings.Config) error {
if config.StorageType == settings.LocalFileSystemObjectStorageType {
avatarStorage, err := NewLocalFileSystemObjectStorage(config, avatarPathPrefix)
Container.AvatarCurrentStorage = avatarStorage
return err
} else if config.StorageType == settings.MinIOStorageType {
avatarStorage, err := NewMinIOObjectStorage(config, avatarPathPrefix)
Container.AvatarCurrentStorage = avatarStorage
avatarStorage, err := newObjectStorage(config, avatarPathPrefix)
if err != nil {
return err
}
return errs.ErrInvalidStorageType
Container.AvatarCurrentStorage = avatarStorage
transactionPictureStorage, err := newObjectStorage(config, transactionPicturePathPrefix)
if err != nil {
return err
}
Container.TransactionPictureCurrentStorage = transactionPictureStorage
return nil
}
// ExistsAvatar returns whether the avatar file exists from the current avatar object storage
@@ -53,3 +59,33 @@ func (s *StorageContainer) SaveAvatar(path string, object ObjectInStorage) error
func (s *StorageContainer) DeleteAvatar(path string) error {
return s.AvatarCurrentStorage.Delete(path)
}
// ExistsTransactionPicture returns whether the transaction picture file exists from the current transaction picture object storage
func (s *StorageContainer) ExistsTransactionPicture(path string) (bool, error) {
return s.TransactionPictureCurrentStorage.Exists(path)
}
// ReadTransactionPicture returns the transaction picture file from the current transaction picture object storage
func (s *StorageContainer) ReadTransactionPicture(path string) (ObjectInStorage, error) {
return s.TransactionPictureCurrentStorage.Read(path)
}
// SaveTransactionPicture returns whether save the transaction picture file into the current transaction picture object storage successfully
func (s *StorageContainer) SaveTransactionPicture(path string, object ObjectInStorage) error {
return s.TransactionPictureCurrentStorage.Save(path, object)
}
// DeleteTransactionPicture returns whether delete the transaction picture file from the current transaction picture object storage successfully
func (s *StorageContainer) DeleteTransactionPicture(path string) error {
return s.TransactionPictureCurrentStorage.Delete(path)
}
func newObjectStorage(config *settings.Config, pathPrefix string) (ObjectStorage, error) {
if config.StorageType == settings.LocalFileSystemObjectStorageType {
return NewLocalFileSystemObjectStorage(config, pathPrefix)
} else if config.StorageType == settings.MinIOStorageType {
return NewMinIOObjectStorage(config, pathPrefix)
}
return nil, errs.ErrInvalidStorageType
}