@@ -74,10 +74,12 @@ const upload = async (filePath, parts = [], requestUrl) =>{
7474} else {
7575console . log ( chalk . red ( '网络连接异常,请重新执行命令继续上传' ) ) ;
7676logger . error ( `分片(${ currentChunkIndex } )上传时网络连接异常 (path: ${ filePath } ) , url: ${ requestUrl } )` ) ;
77+ await logger . close ( ) ;
7778process . exit ( 1 ) ;
7879}
7980} else {
8081console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
82+ await logger . close ( ) ;
8183process . exit ( 1 ) ;
8284}
8385}
@@ -119,6 +121,7 @@ const upload = async (filePath, parts = [], requestUrl) =>{
119121logger . error ( error . message ) ;
120122logger . error ( error . stack ) ;
121123console . log ( chalk ( error . message ) ) ;
124+ await logger . close ( ) ;
122125process . exit ( 1 ) ;
123126}
124127
@@ -150,6 +153,7 @@ const upload = async (filePath, parts = [], requestUrl) =>{
150153logger . error ( error . message ) ;
151154logger . error ( error . stack ) ;
152155console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
156+ await logger . close ( ) ;
153157process . exit ( 1 ) ;
154158}
155159
@@ -169,6 +173,7 @@ const getFileMD5Success = async (filePath, requestUrl) =>{
169173 Authorization
170174} ) ;
171175if ( res . code ) {
176+ logger . info ( `获取已上传信息错误(1): ${ JSON . stringify ( res ) } (path: ${ filePath } , url: ${ requestUrl } )` ) ;
172177throw ( res . message ) ;
173178}
174179uploadId = res . data . uploadId ;
@@ -181,10 +186,11 @@ const getFileMD5Success = async (filePath, requestUrl) =>{
181186uploadedParts = [ ]
182187}
183188} catch ( error ) {
184- logger . error ( `获取已上传信息错误 (path: ${ filePath } , url: ${ requestUrl } )` ) ;
189+ logger . error ( `获取已上传信息错误(2) (path: ${ filePath } , url: ${ requestUrl } )` ) ;
185190logger . error ( error . message ) ;
186191logger . error ( error . stack ) ;
187192console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
193+ await logger . close ( ) ;
188194process . exit ( 1 ) ;
189195}
190196
@@ -227,13 +233,14 @@ const getFileMD5 = async (filePath, requestUrl) =>{
227233console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
228234logger . error ( error . message ) ;
229235logger . error ( error . stack ) ;
236+ await logger . close ( ) ;
230237process . exit ( 1 ) ;
231238}
232239}
233240
234241const uploadFile = async ( filePath , size , requestUrl ) => {
235242fileSize = size ;
236- logger . info ( `(' ************************ 开始上传 (${ filePath } ) (' ************************` ) ;
243+ logger . info ( `************************ 开始上传 (${ filePath } ) ************************` ) ;
237244await getFileMD5 ( filePath , requestUrl ) ;
238245md5 = '' ;
239246uploadId = '' ;
@@ -262,6 +269,7 @@ const uploadDir = async (dir) =>{
262269console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
263270logger . error ( error . message ) ;
264271logger . error ( error . stack ) ;
272+ await logger . close ( ) ;
265273process . exit ( 1 ) ;
266274} else {
267275return files ;
@@ -290,9 +298,11 @@ const beforeUpload = async (filePath) =>{
290298const isDirectory = stat . isDirectory ( ) ;
291299if ( isDirectory && ! isUploadDir ) {
292300console . log ( chalk . red ( `\n${ filePath } 不合法,需指定一个文件\n` ) )
301+ await logger . close ( ) ;
293302process . exit ( 1 ) ;
294303} else if ( ! isDirectory && isUploadDir ) {
295304console . log ( chalk . red ( `\n${ filePath } 不合法,需指定一个文件夹\n` ) )
305+ await logger . close ( ) ;
296306process . exit ( 1 ) ;
297307}
298308fSize = stat . size ;
@@ -304,6 +314,7 @@ const beforeUpload = async (filePath) =>{
304314logger . error ( error . stack ) ;
305315console . log ( chalk . red ( ( error . response && error . response . data ) || error . message ) ) ;
306316}
317+ await logger . close ( ) ;
307318process . exit ( 1 ) ;
308319}
309320if ( isUploadDir ) {
@@ -313,16 +324,18 @@ const beforeUpload = async (filePath) =>{
313324}
314325}
315326
316- const onUpload = ( _username , _password ) => {
327+ const onUpload = async ( _username , _password ) => {
317328Authorization = generateAuthorization ( _username , _password ) ;
318329
319330logger . info ( '************************ 准备上传 ************************' )
320331
321332if ( path . isAbsolute ( argv . path ) ) {
322- beforeUpload ( argv . path ) ;
333+ await beforeUpload ( argv . path ) ;
323334} else {
324- beforeUpload ( path . join ( process . cwd ( ) , argv . path ) )
335+ await beforeUpload ( path . join ( process . cwd ( ) , argv . path ) )
325336}
337+
338+ await logger . close ( ) ;
326339}
327340
328341const [ username , password ] = argv . username . split ( ':' ) ;
0 commit comments