-
Notifications
You must be signed in to change notification settings - Fork 14
/
uploader.go
44 lines (32 loc) · 1.17 KB
/
uploader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package registry
import (
"errors"
"github.com/sarulabs/di"
tusd "github.com/tus/tusd/pkg/handler"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/oss"
"github.com/coretrix/hitrix/service/component/uploader"
"github.com/coretrix/hitrix/service/component/uploader/locker"
)
func ServiceProviderUploader(c tusd.Config, getLockerFunc locker.GetLockerFunc) *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.UploaderService,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
bucket, ok := configService.String("oss.uploader.bucket")
if !ok {
panic(errors.New("missing uploader bucket"))
}
osService := ctn.Get(service.OSService).(oss.IProvider)
composer := tusd.NewStoreComposer()
store := uploader.GetStore(osService.GetClient(), osService.GetUploaderBucketConfig().Name)
store.UseIn(composer)
if getLockerFunc != nil {
composer.UseLocker(getLockerFunc(ctn))
}
c.StoreComposer = composer
return uploader.NewTUSDUploader(c, bucket), nil
},
}
}