refactor: use a lazy setter approach for storageProtocol
This commit is contained in:
parent
97297036c7
commit
0ac4d318b7
|
@ -51,11 +51,10 @@ type S5ProtocolParams struct {
|
||||||
|
|
||||||
type S5ProtocolResult struct {
|
type S5ProtocolResult struct {
|
||||||
fx.Out
|
fx.Out
|
||||||
Protocol registry.Protocol `group:"protocol"`
|
Protocol registry.Protocol `group:"protocol"`
|
||||||
S5Protocol *S5Protocol
|
S5Protocol *S5Protocol
|
||||||
S5NodeConfig *s5config.NodeConfig
|
S5NodeConfig *s5config.NodeConfig
|
||||||
Db *bolt.DB
|
Db *bolt.DB
|
||||||
StorageProtocol storage.StorageProtocol
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type S5ProviderStoreParams struct {
|
type S5ProviderStoreParams struct {
|
||||||
|
@ -93,11 +92,10 @@ func NewS5Protocol(
|
||||||
}
|
}
|
||||||
|
|
||||||
return S5ProtocolResult{
|
return S5ProtocolResult{
|
||||||
Protocol: proto,
|
Protocol: proto,
|
||||||
S5Protocol: proto,
|
S5Protocol: proto,
|
||||||
S5NodeConfig: cfg,
|
S5NodeConfig: cfg,
|
||||||
Db: cfg.DB,
|
Db: cfg.DB,
|
||||||
StorageProtocol: GetStorageProtocol(proto),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +180,8 @@ func (s *S5Protocol) Init(args ...any) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.tusHandler.SetStorageProtocol(GetStorageProtocol(s))
|
||||||
|
|
||||||
err = s.tusHandler.Init()
|
err = s.tusHandler.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -58,26 +58,24 @@ type TusHandler struct {
|
||||||
|
|
||||||
type TusHandlerParams struct {
|
type TusHandlerParams struct {
|
||||||
fx.In
|
fx.In
|
||||||
Config *viper.Viper
|
Config *viper.Viper
|
||||||
Logger *zap.Logger
|
Logger *zap.Logger
|
||||||
Db *gorm.DB
|
Db *gorm.DB
|
||||||
Cron *cron.CronServiceDefault
|
Cron *cron.CronServiceDefault
|
||||||
Storage storage.StorageService
|
Storage storage.StorageService
|
||||||
Accounts *account.AccountServiceDefault
|
Accounts *account.AccountServiceDefault
|
||||||
Metadata metadata.MetadataService
|
Metadata metadata.MetadataService
|
||||||
StorageProtocol storage.StorageProtocol
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTusHandler(params TusHandlerParams) *TusHandler {
|
func NewTusHandler(params TusHandlerParams) *TusHandler {
|
||||||
return &TusHandler{
|
return &TusHandler{
|
||||||
config: params.Config,
|
config: params.Config,
|
||||||
db: params.Db,
|
db: params.Db,
|
||||||
logger: params.Logger,
|
logger: params.Logger,
|
||||||
cron: params.Cron,
|
cron: params.Cron,
|
||||||
storage: params.Storage,
|
storage: params.Storage,
|
||||||
accounts: params.Accounts,
|
accounts: params.Accounts,
|
||||||
metadata: params.Metadata,
|
metadata: params.Metadata,
|
||||||
storageProtocol: params.StorageProtocol,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,6 +314,10 @@ func (t *TusHandler) GetUploadReader(ctx context.Context, hash []byte, start int
|
||||||
return reader, nil
|
return reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TusHandler) SetStorageProtocol(storageProtocol storage.StorageProtocol) {
|
||||||
|
t.storageProtocol = storageProtocol
|
||||||
|
}
|
||||||
|
|
||||||
func (t *TusHandler) uploadTask(ctx context.Context, upload *models.TusUpload) error {
|
func (t *TusHandler) uploadTask(ctx context.Context, upload *models.TusUpload) error {
|
||||||
tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID)
|
tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue