|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package local
-
- import (
- "fmt"
-
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg"
- stgtypes "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
- jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
- )
-
- func init() {
- reg.RegisterBuilder[*jcstypes.LocalType](func(detail *jcstypes.UserSpaceDetail) stgtypes.StorageBuilder {
- return &builder{
- detail: detail,
- }
- })
- }
-
- type builder struct {
- stgtypes.EmptyBuilder
- detail *jcstypes.UserSpaceDetail
- }
-
- func (b *builder) FeatureDesc() stgtypes.FeatureDesc {
- return stgtypes.FeatureDesc{}
- }
-
- func (b *builder) CreateShardStore(typeOnly bool) (stgtypes.ShardStore, error) {
- cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred)
- if !ok {
- return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential)
- }
-
- if typeOnly {
- return (*ShardStore)(nil), nil
- }
-
- return NewShardStore(cred.RootDir, b.detail)
- }
-
- func (b *builder) CreateBaseStore(typeOnly bool) (stgtypes.BaseStore, error) {
- cred, ok := b.detail.UserSpace.Credential.(*jcstypes.LocalCred)
- if !ok {
- return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential)
- }
-
- if typeOnly {
- return (*BaseStore)(nil), nil
- }
-
- return NewBaseStore(cred.RootDir, b.detail)
- }
-
- func (b *builder) CreateMultiparter(typeOnly bool) (stgtypes.Multiparter, error) {
- feat := stgtypes.FindFeature[*jcstypes.MultipartUploadFeature](b.detail)
- if feat == nil {
- return nil, fmt.Errorf("feature %T not found", jcstypes.MultipartUploadFeature{})
- }
-
- if typeOnly {
- return (*Multiparter)(nil), nil
- }
-
- return &Multiparter{
- feat: feat,
- }, nil
- }
-
- func (b *builder) CreateS2STransfer(typeOnly bool) (stgtypes.S2STransfer, error) {
- feat := stgtypes.FindFeature[*jcstypes.S2STransferFeature](b.detail)
- if feat == nil {
- return nil, fmt.Errorf("feature %T not found", jcstypes.S2STransferFeature{})
- }
-
- if typeOnly {
- return (*S2STransfer)(nil), nil
- }
-
- return &S2STransfer{
- detail: b.detail,
- }, nil
- }
|