84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package local
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
|
|
"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg"
|
|
"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
|
|
cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types"
|
|
)
|
|
|
|
func init() {
|
|
reg.RegisterBuilder[*cortypes.LocalType](func(detail *clitypes.UserSpaceDetail) types.StorageBuilder {
|
|
return &builder{
|
|
detail: detail,
|
|
}
|
|
})
|
|
}
|
|
|
|
type builder struct {
|
|
types.EmptyBuilder
|
|
detail *clitypes.UserSpaceDetail
|
|
}
|
|
|
|
func (b *builder) FeatureDesc() types.FeatureDesc {
|
|
return types.FeatureDesc{}
|
|
}
|
|
|
|
func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) {
|
|
cred, ok := b.detail.UserSpace.Credential.(*cortypes.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) (types.BaseStore, error) {
|
|
cred, ok := b.detail.UserSpace.Credential.(*cortypes.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) (types.Multiparter, error) {
|
|
feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail)
|
|
if feat == nil {
|
|
return nil, fmt.Errorf("feature %T not found", cortypes.MultipartUploadFeature{})
|
|
}
|
|
|
|
if typeOnly {
|
|
return (*Multiparter)(nil), nil
|
|
}
|
|
|
|
return &Multiparter{
|
|
feat: feat,
|
|
}, nil
|
|
}
|
|
|
|
func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) {
|
|
feat := types.FindFeature[*cortypes.S2STransferFeature](b.detail)
|
|
if feat == nil {
|
|
return nil, fmt.Errorf("feature %T not found", cortypes.S2STransferFeature{})
|
|
}
|
|
|
|
if typeOnly {
|
|
return (*S2STransfer)(nil), nil
|
|
}
|
|
|
|
return &S2STransfer{
|
|
detail: b.detail,
|
|
}, nil
|
|
}
|