-
Notifications
You must be signed in to change notification settings - Fork 14
/
uploader.go
104 lines (83 loc) · 2.64 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package uploader
import (
"net/http"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/tus/tusd/pkg/gcsstore"
"github.com/tus/tusd/pkg/s3store"
tusd "github.com/tus/tusd/pkg/handler"
"cloud.google.com/go/storage"
)
type Uploader interface {
PostFile(w http.ResponseWriter, r *http.Request)
PatchFile(w http.ResponseWriter, r *http.Request)
DelFile(w http.ResponseWriter, r *http.Request)
GetFile(w http.ResponseWriter, r *http.Request)
HeadFile(w http.ResponseWriter, r *http.Request)
Middleware(h http.Handler) http.Handler
SupportedExtensions() string
Metrics() tusd.Metrics
GetCreatedUploadsChan() chan tusd.HookEvent
GetCompletedUploadsChan() chan tusd.HookEvent
GetTerminatedUploadsChan() chan tusd.HookEvent
GetUploadProgressChan() chan tusd.HookEvent
GetBucket() string
}
type TUSDUploader struct {
handler *tusd.UnroutedHandler
bucket string
}
func GetStore(OSSClient interface{}, bucket string) Store {
if _, ok := OSSClient.(storage.Client); ok {
return &GoogleStore{store: gcsstore.New(bucket, OSSClient.(gcsstore.GCSAPI))}
}
if _, ok := OSSClient.(*s3.S3); ok {
return &AmazonStore{store: s3store.New(bucket, OSSClient.(s3store.S3API))}
}
panic("OSSClient store not found")
}
func NewTUSDUploader(c tusd.Config, bucket string) Uploader {
uploader, err := tusd.NewUnroutedHandler(c)
if err != nil {
panic(err)
}
return &TUSDUploader{handler: uploader, bucket: bucket}
}
func (u *TUSDUploader) GetBucket() string {
return u.bucket
}
func (u *TUSDUploader) PostFile(w http.ResponseWriter, r *http.Request) {
u.handler.PostFile(w, r)
}
func (u *TUSDUploader) PatchFile(w http.ResponseWriter, r *http.Request) {
u.handler.PatchFile(w, r)
}
func (u *TUSDUploader) DelFile(w http.ResponseWriter, r *http.Request) {
u.handler.DelFile(w, r)
}
func (u *TUSDUploader) GetFile(w http.ResponseWriter, r *http.Request) {
u.handler.GetFile(w, r)
}
func (u *TUSDUploader) HeadFile(w http.ResponseWriter, r *http.Request) {
u.handler.HeadFile(w, r)
}
func (u *TUSDUploader) Middleware(h http.Handler) http.Handler {
return u.handler.Middleware(h)
}
func (u *TUSDUploader) SupportedExtensions() string {
return u.handler.SupportedExtensions()
}
func (u *TUSDUploader) Metrics() tusd.Metrics {
return u.handler.Metrics
}
func (u *TUSDUploader) GetCreatedUploadsChan() chan tusd.HookEvent {
return u.handler.CreatedUploads
}
func (u *TUSDUploader) GetCompletedUploadsChan() chan tusd.HookEvent {
return u.handler.CompleteUploads
}
func (u *TUSDUploader) GetTerminatedUploadsChan() chan tusd.HookEvent {
return u.handler.TerminatedUploads
}
func (u *TUSDUploader) GetUploadProgressChan() chan tusd.HookEvent {
return u.handler.UploadProgress
}