mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-28 02:31:34 +08:00
@@ -36,6 +36,7 @@ func init() {
|
||||
RegisterStorageFactory(string(types.StorageTypeLocal), newLocalStorageConfig)
|
||||
RegisterStorageFactory(string(types.StorageTypeAlist), newAlistStorageConfig)
|
||||
RegisterStorageFactory(string(types.StorageTypeWebdav), newWebdavStorageConfig)
|
||||
RegisterStorageFactory(string(types.StorageTypeMinio), newMinioStorageConfig)
|
||||
}
|
||||
|
||||
func newLocalStorageConfig(cfg *NewStorageConfig) (StorageConfig, error) {
|
||||
@@ -102,3 +103,12 @@ func LoadStorageConfigs(v *viper.Viper) ([]StorageConfig, error) {
|
||||
|
||||
return configs, nil
|
||||
}
|
||||
|
||||
func newMinioStorageConfig(cfg *NewStorageConfig) (StorageConfig, error) {
|
||||
var minioCfg MinioStorageConfig
|
||||
minioCfg.NewStorageConfig = *cfg
|
||||
if err := mapstructure.Decode(cfg.RawConfig, &minioCfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode minio storage config: %w", err)
|
||||
}
|
||||
return &minioCfg, nil
|
||||
}
|
||||
|
||||
@@ -104,3 +104,37 @@ func (w *WebdavStorageConfig) GetType() types.StorageType {
|
||||
func (w *WebdavStorageConfig) GetName() string {
|
||||
return w.Name
|
||||
}
|
||||
|
||||
type MinioStorageConfig struct {
|
||||
NewStorageConfig
|
||||
Endpoint string `toml:"endpoint" mapstructure:"endpoint" json:"endpoint"`
|
||||
AccessKeyID string `toml:"access_key_id" mapstructure:"access_key_id" json:"access_key_id"`
|
||||
SecretAccessKey string `toml:"secret_access_key" mapstructure:"secret_access_key" json:"secret_access_key"`
|
||||
BucketName string `toml:"bucket_name" mapstructure:"bucket_name" json:"bucket_name"`
|
||||
UseSSL bool `toml:"use_ssl" mapstructure:"use_ssl" json:"use_ssl"`
|
||||
BasePath string `toml:"base_path" mapstructure:"base_path" json:"base_path"`
|
||||
}
|
||||
|
||||
func (m *MinioStorageConfig) Validate() error {
|
||||
if m.Endpoint == "" {
|
||||
return fmt.Errorf("endpoint is required for minio storage")
|
||||
}
|
||||
if m.AccessKeyID == "" || m.SecretAccessKey == "" {
|
||||
return fmt.Errorf("access_key_id and secret_access_key are required for minio storage")
|
||||
}
|
||||
if m.BucketName == "" {
|
||||
return fmt.Errorf("bucket_name is required for minio storage")
|
||||
}
|
||||
if m.BasePath == "" {
|
||||
return fmt.Errorf("base_path is required for minio storage")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MinioStorageConfig) GetType() types.StorageType {
|
||||
return types.StorageTypeMinio
|
||||
}
|
||||
|
||||
func (m *MinioStorageConfig) GetName() string {
|
||||
return m.Name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user