refactor: use a lazy setter approach for storageProtocol

This commit is contained in:
Derrick Hammer 2024-02-17 04:41:12 -05:00
parent 97297036c7
commit 0ac4d318b7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 28 additions and 26 deletions

View File

@ -55,7 +55,6 @@ type S5ProtocolResult struct {
S5Protocol *S5Protocol
S5NodeConfig *s5config.NodeConfig
Db *bolt.DB
StorageProtocol storage.StorageProtocol
}
type S5ProviderStoreParams struct {
@ -97,7 +96,6 @@ func NewS5Protocol(
S5Protocol: proto,
S5NodeConfig: cfg,
Db: cfg.DB,
StorageProtocol: GetStorageProtocol(proto),
}, nil
}
@ -182,6 +180,8 @@ func (s *S5Protocol) Init(args ...any) error {
return err
}
s.tusHandler.SetStorageProtocol(GetStorageProtocol(s))
err = s.tusHandler.Init()
if err != nil {
return err

View File

@ -65,7 +65,6 @@ type TusHandlerParams struct {
Storage storage.StorageService
Accounts *account.AccountServiceDefault
Metadata metadata.MetadataService
StorageProtocol storage.StorageProtocol
}
func NewTusHandler(params TusHandlerParams) *TusHandler {
@ -77,7 +76,6 @@ func NewTusHandler(params TusHandlerParams) *TusHandler {
storage: params.Storage,
accounts: params.Accounts,
metadata: params.Metadata,
storageProtocol: params.StorageProtocol,
}
}
@ -316,6 +314,10 @@ func (t *TusHandler) GetUploadReader(ctx context.Context, hash []byte, start int
return reader, nil
}
func (t *TusHandler) SetStorageProtocol(storageProtocol storage.StorageProtocol) {
t.storageProtocol = storageProtocol
}
func (t *TusHandler) uploadTask(ctx context.Context, upload *models.TusUpload) error {
tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID)
if err != nil {