mirror of
https://github.com/ente-io/ente.git
synced 2025-05-29 05:51:19 +00:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package s3config
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/ente-io/museum/ente"
|
|
"strings"
|
|
)
|
|
|
|
type ObjectBucketConfig struct {
|
|
PrimaryBucket string `mapstructure:"primaryBucket"`
|
|
ReplicaBuckets []string `mapstructure:"replicaBuckets"`
|
|
}
|
|
|
|
type FileDataConfig struct {
|
|
ObjectBucketConfig map[string]ObjectBucketConfig `mapstructure:"file-data-config"`
|
|
}
|
|
|
|
func (f FileDataConfig) HasConfig(objectType ente.ObjectType) bool {
|
|
if objectType == "" || objectType == ente.FILE || objectType == ente.THUMBNAIL {
|
|
panic(fmt.Sprintf("Unsupported object type: %s", objectType))
|
|
}
|
|
|
|
_, ok := f.ObjectBucketConfig[key(objectType)]
|
|
return ok
|
|
}
|
|
|
|
func (f FileDataConfig) GetPrimaryBucketID(objectType ente.ObjectType) string {
|
|
config, ok := f.ObjectBucketConfig[key(objectType)]
|
|
if !ok {
|
|
panic(fmt.Sprintf("No config for object type: %s, use HasConfig", key(objectType)))
|
|
}
|
|
return config.PrimaryBucket
|
|
}
|
|
|
|
func (f FileDataConfig) GetReplicaBuckets(objectType ente.ObjectType) []string {
|
|
config, ok := f.ObjectBucketConfig[key(objectType)]
|
|
if !ok {
|
|
panic(fmt.Sprintf("No config for object type: %s, use HasConfig", key(objectType)))
|
|
}
|
|
return config.ReplicaBuckets
|
|
}
|
|
|
|
func key(oType ente.ObjectType) string {
|
|
return strings.ToLower(string(oType))
|
|
}
|