refactor: swap Protocol for to StorageProtocol
This commit is contained in:
parent
b52383b123
commit
97297036c7
|
@ -43,40 +43,41 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TusHandler struct {
|
type TusHandler struct {
|
||||||
config *viper.Viper
|
config *viper.Viper
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
cron *cron.CronServiceDefault
|
cron *cron.CronServiceDefault
|
||||||
storage storage.StorageService
|
storage storage.StorageService
|
||||||
accounts *account.AccountServiceDefault
|
accounts *account.AccountServiceDefault
|
||||||
metadata metadata.MetadataService
|
metadata metadata.MetadataService
|
||||||
tus *tusd.Handler
|
tus *tusd.Handler
|
||||||
tusStore tusd.DataStore
|
tusStore tusd.DataStore
|
||||||
s3Client *s3.Client
|
s3Client *s3.Client
|
||||||
protocol *S5Protocol
|
storageProtocol storage.StorageProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
Protocol *S5Protocol
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,16 +374,14 @@ func (t *TusHandler) uploadTask(ctx context.Context, upload *models.TusUpload) e
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
storageProtocol := GetStorageProtocol(t.protocol)
|
uploadMeta, err := t.storage.UploadObject(ctx, t.storageProtocol, nil, &renter.MultiPartUploadParams{
|
||||||
|
|
||||||
uploadMeta, err := t.storage.UploadObject(ctx, storageProtocol, nil, &renter.MultiPartUploadParams{
|
|
||||||
ReaderFactory: func(start uint, end uint) (io.ReadCloser, error) {
|
ReaderFactory: func(start uint, end uint) (io.ReadCloser, error) {
|
||||||
rangeHeader := fmt.Sprintf("bytes=%d-%d", start, end)
|
rangeHeader := fmt.Sprintf("bytes=%d-%d", start, end)
|
||||||
ctx = context.WithValue(ctx, "range", rangeHeader)
|
ctx = context.WithValue(ctx, "range", rangeHeader)
|
||||||
return tusUpload.GetReader(ctx)
|
return tusUpload.GetReader(ctx)
|
||||||
},
|
},
|
||||||
Bucket: upload.Protocol,
|
Bucket: upload.Protocol,
|
||||||
FileName: "/" + storageProtocol.EncodeFileName(dbHash),
|
FileName: "/" + t.storageProtocol.EncodeFileName(dbHash),
|
||||||
Size: uint64(info.Size),
|
Size: uint64(info.Size),
|
||||||
}, proof)
|
}, proof)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue