@@ -74,10 +74,12 @@ const upload = async (filePath, parts = [], requestUrl) => {
74
74
} else {
75
75
console . log ( chalk . red ( '网络连接异常,请重新执行命令继续上传' ) ) ;
76
76
logger . error ( `分片(${ currentChunkIndex } )上传时网络连接异常 (path: ${ filePath } ) , url: ${ requestUrl } )` ) ;
77
+ await logger . close ( ) ;
77
78
process . exit ( 1 ) ;
78
79
}
79
80
} else {
80
81
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
82
+ await logger . close ( ) ;
81
83
process . exit ( 1 ) ;
82
84
}
83
85
}
@@ -119,6 +121,7 @@ const upload = async (filePath, parts = [], requestUrl) => {
119
121
logger . error ( error . message ) ;
120
122
logger . error ( error . stack ) ;
121
123
console . log ( chalk ( error . message ) ) ;
124
+ await logger . close ( ) ;
122
125
process . exit ( 1 ) ;
123
126
}
124
127
@@ -150,6 +153,7 @@ const upload = async (filePath, parts = [], requestUrl) => {
150
153
logger . error ( error . message ) ;
151
154
logger . error ( error . stack ) ;
152
155
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
156
+ await logger . close ( ) ;
153
157
process . exit ( 1 ) ;
154
158
}
155
159
@@ -169,6 +173,7 @@ const getFileMD5Success = async (filePath, requestUrl) => {
169
173
Authorization
170
174
} ) ;
171
175
if ( res . code ) {
176
+ logger . info ( `获取已上传信息错误(1): ${ JSON . stringify ( res ) } (path: ${ filePath } , url: ${ requestUrl } )` ) ;
172
177
throw ( res . message ) ;
173
178
}
174
179
uploadId = res . data . uploadId ;
@@ -181,10 +186,11 @@ const getFileMD5Success = async (filePath, requestUrl) => {
181
186
uploadedParts = [ ]
182
187
}
183
188
} catch ( error ) {
184
- logger . error ( `获取已上传信息错误 (path: ${ filePath } , url: ${ requestUrl } )` ) ;
189
+ logger . error ( `获取已上传信息错误(2) (path: ${ filePath } , url: ${ requestUrl } )` ) ;
185
190
logger . error ( error . message ) ;
186
191
logger . error ( error . stack ) ;
187
192
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
193
+ await logger . close ( ) ;
188
194
process . exit ( 1 ) ;
189
195
}
190
196
@@ -227,13 +233,14 @@ const getFileMD5 = async (filePath, requestUrl) => {
227
233
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
228
234
logger . error ( error . message ) ;
229
235
logger . error ( error . stack ) ;
236
+ await logger . close ( ) ;
230
237
process . exit ( 1 ) ;
231
238
}
232
239
}
233
240
234
241
const uploadFile = async ( filePath , size , requestUrl ) => {
235
242
fileSize = size ;
236
- logger . info ( `(' ************************ 开始上传 (${ filePath } ) (' ************************` ) ;
243
+ logger . info ( `************************ 开始上传 (${ filePath } ) ************************` ) ;
237
244
await getFileMD5 ( filePath , requestUrl ) ;
238
245
md5 = '' ;
239
246
uploadId = '' ;
@@ -262,6 +269,7 @@ const uploadDir = async (dir) => {
262
269
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
263
270
logger . error ( error . message ) ;
264
271
logger . error ( error . stack ) ;
272
+ await logger . close ( ) ;
265
273
process . exit ( 1 ) ;
266
274
} else {
267
275
return files ;
@@ -290,9 +298,11 @@ const beforeUpload = async (filePath) => {
290
298
const isDirectory = stat . isDirectory ( ) ;
291
299
if ( isDirectory && ! isUploadDir ) {
292
300
console . log ( chalk . red ( `\n${ filePath } 不合法,需指定一个文件\n` ) )
301
+ await logger . close ( ) ;
293
302
process . exit ( 1 ) ;
294
303
} else if ( ! isDirectory && isUploadDir ) {
295
304
console . log ( chalk . red ( `\n${ filePath } 不合法,需指定一个文件夹\n` ) )
305
+ await logger . close ( ) ;
296
306
process . exit ( 1 ) ;
297
307
}
298
308
fSize = stat . size ;
@@ -304,6 +314,7 @@ const beforeUpload = async (filePath) => {
304
314
logger . error ( error . stack ) ;
305
315
console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
306
316
}
317
+ await logger . close ( ) ;
307
318
process . exit ( 1 ) ;
308
319
}
309
320
if ( isUploadDir ) {
@@ -313,16 +324,18 @@ const beforeUpload = async (filePath) => {
313
324
}
314
325
}
315
326
316
- const onUpload = ( _username , _password ) => {
327
+ const onUpload = async ( _username , _password ) => {
317
328
Authorization = generateAuthorization ( _username , _password ) ;
318
329
319
330
logger . info ( '************************ 准备上传 ************************' )
320
331
321
332
if ( path . isAbsolute ( argv . path ) ) {
322
- beforeUpload ( argv . path ) ;
333
+ await beforeUpload ( argv . path ) ;
323
334
} else {
324
- beforeUpload ( path . join ( process . cwd ( ) , argv . path ) )
335
+ await beforeUpload ( path . join ( process . cwd ( ) , argv . path ) )
325
336
}
337
+
338
+ await logger . close ( ) ;
326
339
}
327
340
328
341
const [ username , password ] = argv . username . split ( ':' ) ;
0 commit comments