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

@ -51,11 +51,10 @@ type S5ProtocolParams struct {
type S5ProtocolResult struct {
fx.Out
Protocol registry.Protocol `group:"protocol"`
S5Protocol *S5Protocol
S5NodeConfig *s5config.NodeConfig
Db *bolt.DB
StorageProtocol storage.StorageProtocol
Protocol registry.Protocol `group:"protocol"`
S5Protocol *S5Protocol
S5NodeConfig *s5config.NodeConfig
Db *bolt.DB
}
type S5ProviderStoreParams struct {
@ -93,11 +92,10 @@ func NewS5Protocol(
}
return S5ProtocolResult{
Protocol: proto,
S5Protocol: proto,
S5NodeConfig: cfg,
Db: cfg.DB,
StorageProtocol: GetStorageProtocol(proto),
Protocol: proto,
S5Protocol: proto,
S5NodeConfig: cfg,
Db: cfg.DB,
}, 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

@ -58,26 +58,24 @@ type TusHandler struct {
type TusHandlerParams struct {
fx.In
Config *viper.Viper
Logger *zap.Logger
Db *gorm.DB
Cron *cron.CronServiceDefault
Storage storage.StorageService
Accounts *account.AccountServiceDefault
Metadata metadata.MetadataService
StorageProtocol storage.StorageProtocol
Config *viper.Viper
Logger *zap.Logger
Db *gorm.DB
Cron *cron.CronServiceDefault
Storage storage.StorageService
Accounts *account.AccountServiceDefault
Metadata metadata.MetadataService
}
func NewTusHandler(params TusHandlerParams) *TusHandler {
return &TusHandler{
config: params.Config,
db: params.Db,
logger: params.Logger,
cron: params.Cron,
storage: params.Storage,
accounts: params.Accounts,
metadata: params.Metadata,
storageProtocol: params.StorageProtocol,
config: params.Config,
db: params.Db,
logger: params.Logger,
cron: params.Cron,
storage: params.Storage,
accounts: params.Accounts,
metadata: params.Metadata,
}
}
@ -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 {