tt-uploader 1.6.2 → 2.0.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +211 -3
- package/dist/index.js +1 -1
- package/package.json +4 -3
- package/types/index.d.ts +61 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tt-uploader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta",
|
|
4
4
|
"description": "upload component for veVod and veImageX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"types"
|
|
12
|
+
"types",
|
|
13
|
+
"CHANGELOG.md"
|
|
13
14
|
],
|
|
14
15
|
"publishConfig": {
|
|
15
16
|
"registry": "https://registry.npmjs.org"
|
|
@@ -24,4 +25,4 @@
|
|
|
24
25
|
"eventemitter3": "^5.0.1",
|
|
25
26
|
"jsrsasign": "^10.8.6"
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
export interface CredentialRefreshContext {
|
|
2
|
+
key: string
|
|
3
|
+
reason: 'expiring' | 'expired'
|
|
4
|
+
expiresAt: string
|
|
5
|
+
}
|
|
6
|
+
export interface PresignedRefreshContext extends CredentialRefreshContext {
|
|
7
|
+
uploadHost: string
|
|
8
|
+
storeUri: string
|
|
9
|
+
sessionKey: string
|
|
10
|
+
}
|
|
11
|
+
export interface PresignedUploadSuccess {
|
|
12
|
+
key: string
|
|
13
|
+
sessionKey: string
|
|
14
|
+
storeUri: string
|
|
15
|
+
uploadHost: string
|
|
16
|
+
fileName: string
|
|
17
|
+
fileSize: number
|
|
18
|
+
fileType: 'video' | 'image' | 'object' | 'media'
|
|
19
|
+
}
|
|
20
|
+
export interface PresignedConfig {
|
|
21
|
+
/** Renew credentials for the SAME uploadHost/storeUri/sessionKey; never re-Apply. */
|
|
22
|
+
onRefreshUploadInfo?: (context: PresignedRefreshContext) => Promise<PresignedUploadInfo>
|
|
23
|
+
|
|
24
|
+
/** Called once after file transfer; complete does not await the returned promise. */
|
|
25
|
+
onUploadSuccess?: (params: PresignedUploadSuccess) => void | Promise<unknown>
|
|
26
|
+
}
|
|
27
|
+
export interface PresignedCallbackError {
|
|
28
|
+
error: unknown
|
|
29
|
+
params: PresignedUploadSuccess
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PresignedUploadInfo {
|
|
33
|
+
uploadHost: string
|
|
34
|
+
storeUri: string
|
|
35
|
+
auth: string
|
|
36
|
+
sessionKey: string
|
|
37
|
+
uploadHeaders?: Record<string, string>
|
|
38
|
+
expiresAt?: string
|
|
39
|
+
}
|
|
40
|
+
export interface PresignedFileOption {
|
|
41
|
+
file: File | Blob
|
|
42
|
+
type?: 'video' | 'image' | 'object' | 'media'
|
|
43
|
+
uploadInfo: PresignedUploadInfo
|
|
44
|
+
}
|
|
45
|
+
|
|
1
46
|
export interface STSToken {
|
|
2
47
|
AccessKeyId: string
|
|
3
48
|
SecretAccessKey: string
|
|
@@ -38,6 +83,11 @@ export interface ObjectConfig {
|
|
|
38
83
|
}
|
|
39
84
|
|
|
40
85
|
export interface InitConfig {
|
|
86
|
+
onRefreshStsToken?: (context: CredentialRefreshContext) => Promise<STSToken>
|
|
87
|
+
/** Refresh at request boundaries, default 60000 ms before expiry. */
|
|
88
|
+
credentialRefreshWindowMs?: number
|
|
89
|
+
|
|
90
|
+
presignedConfig?: PresignedConfig
|
|
41
91
|
userId: string
|
|
42
92
|
appId: number
|
|
43
93
|
videoConfig?: VideoConfig
|
|
@@ -47,6 +97,8 @@ export interface InitConfig {
|
|
|
47
97
|
noLog?: boolean
|
|
48
98
|
useServerCurrentTime?: boolean
|
|
49
99
|
taskParallelLimit?: number
|
|
100
|
+
/** Maximum concurrent parts per file. Default: 8. */
|
|
101
|
+
uploadSliceCount?: number
|
|
50
102
|
region?:string
|
|
51
103
|
processRate?:number
|
|
52
104
|
cnOrOverseas?:'cn' | 'overseas'
|
|
@@ -68,6 +120,10 @@ export interface InitConfig {
|
|
|
68
120
|
}
|
|
69
121
|
|
|
70
122
|
export interface UpdateOptions {
|
|
123
|
+
onRefreshStsToken?: (context: CredentialRefreshContext) => Promise<STSToken>
|
|
124
|
+
credentialRefreshWindowMs?: number
|
|
125
|
+
|
|
126
|
+
presignedConfig?: PresignedConfig
|
|
71
127
|
userId?: string
|
|
72
128
|
appId?: number
|
|
73
129
|
videoConfig?: VideoConfig
|
|
@@ -115,6 +171,7 @@ export interface ImageXFileOption {
|
|
|
115
171
|
export default class TTUploader {
|
|
116
172
|
constructor(options: InitConfig)
|
|
117
173
|
setOption(options: UpdateOptions): void
|
|
174
|
+
addPresignedFile(options: PresignedFileOption): string
|
|
118
175
|
addFile(options: VodFileOption): string
|
|
119
176
|
addVodFile(option: VodFileOption): string
|
|
120
177
|
addImageFile(option: ImageXFileOption): string
|
|
@@ -126,10 +183,13 @@ export default class TTUploader {
|
|
|
126
183
|
pause(key?: string): void
|
|
127
184
|
cancel(key?: string): void
|
|
128
185
|
removeFile(key?: string): void
|
|
186
|
+
on(eventName: 'callbackError', callback: (info: PresignedCallbackError) => void): void
|
|
129
187
|
on(eventName: 'complete' | 'error' | 'progress', callback: (info: Record<string, any>) => void): void
|
|
188
|
+
once(eventName: 'callbackError', callback: (info: PresignedCallbackError) => void): void
|
|
130
189
|
once(eventName: 'complete' | 'error' | 'progress', callback: (info: Record<string, any>) => void): void
|
|
190
|
+
removeListener(eventName: 'callbackError', callback: (info: PresignedCallbackError) => void): void
|
|
131
191
|
removeListener(eventName: 'complete' | 'error' | 'progress', callback: (info: Record<string, any>) => void): void
|
|
132
|
-
removeAllListeners(eventName: 'complete' | 'error' | 'progress'): void
|
|
192
|
+
removeAllListeners(eventName: 'callbackError' | 'complete' | 'error' | 'progress'): void
|
|
133
193
|
use(plugin: any): void
|
|
134
194
|
refreshStsToken(newToken: STSToken): void
|
|
135
195
|
}
|