@@ -64,6 +64,9 @@ class InitPartUploadTask implements Task {
64
64
const filenameResult = await this . file . name ( )
65
65
if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
66
66
67
+ const fileKeyResult = await this . file . key ( )
68
+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
69
+
67
70
// 首先检查 context 上的 upload id 有没有过期
68
71
if ( this . context . uploadPartId ) {
69
72
const nowTime = Date . now ( ) / 1e3
@@ -75,9 +78,9 @@ class InitPartUploadTask implements Task {
75
78
abort : this . abort ,
76
79
token : this . context ! . token ! ,
77
80
bucket : this . context . token ! . bucket ,
78
- key : filenameResult . result || undefined ,
79
81
uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
80
82
uploadId : this . context . uploadPartId . uploadId ,
83
+ key : fileKeyResult . result || filenameResult . result || undefined ,
81
84
onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
82
85
} )
83
86
@@ -105,8 +108,8 @@ class InitPartUploadTask implements Task {
105
108
abort : this . abort ,
106
109
token : this . context ! . token ! ,
107
110
bucket : this . context ! . token ! . bucket ,
108
- key : filenameResult . result || undefined ,
109
111
uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
112
+ key : fileKeyResult . result || filenameResult . result || undefined ,
110
113
onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
111
114
} )
112
115
@@ -168,6 +171,9 @@ class UploadPartTask implements Task {
168
171
const filenameResult = await this . file . name ( )
169
172
if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
170
173
174
+ const fileKeyResult = await this . file . key ( )
175
+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
176
+
171
177
const fileSizeResult = await this . file . size ( )
172
178
if ( ! isSuccessResult ( fileSizeResult ) ) return fileSizeResult
173
179
@@ -178,9 +184,9 @@ class UploadPartTask implements Task {
178
184
partIndex : this . index ,
179
185
token : this . context ! . token ! ,
180
186
bucket : this . context ! . token ! . bucket ,
181
- key : filenameResult . result || undefined ,
182
187
uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
183
188
uploadId : this . context ! . uploadPartId ! . uploadId ! ,
189
+ key : fileKeyResult . result || filenameResult . result || undefined ,
184
190
onProgress : progress => { this . updateProgress ( false , fileSizeResult . result , progress . percent , notify ) }
185
191
} )
186
192
@@ -233,6 +239,10 @@ class CompletePartUploadTask implements Task {
233
239
234
240
async process ( notify : ( ) => void ) : Promise < Result > {
235
241
this . updateProgress ( 0 , notify )
242
+
243
+ const fileKeyResult = await this . file . key ( )
244
+ if ( ! isSuccessResult ( fileKeyResult ) ) return fileKeyResult
245
+
236
246
const filenameResult = await this . file . name ( )
237
247
if ( ! isSuccessResult ( filenameResult ) ) return filenameResult
238
248
@@ -253,10 +263,10 @@ class CompletePartUploadTask implements Task {
253
263
customVars : this . vars ,
254
264
token : this . context ! . token ! ,
255
265
metadata : metadataResult . result ,
256
- key : filenameResult . result || undefined ,
257
266
uploadHostUrl : this . context ! . host ! . getUrl ( ) ,
258
267
mimeType : mimeTypeResult . result || undefined ,
259
268
uploadId : this . context ! . uploadPartId ! . uploadId ! ,
269
+ key : fileKeyResult . result || filenameResult . result || undefined ,
260
270
fileName : filenameResult . result || generateRandomString ( ) , // 和直传行为保持一致
261
271
onProgress : progress => { this . updateProgress ( progress . percent , notify ) }
262
272
} )
0 commit comments