@@ -13,45 +13,38 @@ export const uploadCommand = new Command('upload')
1313 . argument ( '[pattern]' , 'glob pattern' , '*' )
1414 . argument ( '[remote]' , 'remote path' , sep )
1515 . option ( '-t --token [token]' , 'access token' )
16- . option ( '-b --bytes <number>' , 'Split upload bytes size' , Number , 1073741824 )
16+ . option ( '-b --bytes <number>' , 'split upload bytes size' , Number , 1073741824 )
1717 . option ( '--thread' , 'Thread' )
18- . action ( async ( pattern , remote , options , command ) => {
19- const { pcs } = command ;
20-
18+ . action ( async ( pattern , remote , options , { pcs } ) => {
2119 const files = await glob ( pattern , {
2220 nodir : true ,
2321 } ) ;
2422 const { bytes } = options ;
25-
2623 const temp = join ( os . tmpdir ( ) , 'pcs-cli' ) ;
27- try {
28- // 串行上传
29- files . reduce ( async ( previousValue , currentValue ) => {
30- await previousValue ;
31- const fileStat = statSync ( currentValue ) ;
3224
25+ try {
26+ for await ( const file of files ) {
27+ const fileStat = statSync ( file ) ;
3328 if ( Number . isInteger ( bytes ) && fileStat . size > bytes ) {
3429 // 分片上传
35- const pieces = await splitFile ( currentValue , bytes , temp ) ;
30+ const pieces = await splitFile ( file , bytes , temp ) ;
3631 const blocks = [ ] ;
3732
3833 // eslint-disable-next-line no-restricted-syntax
3934 for ( const piece of pieces as string [ ] ) {
4035 //
4136 // eslint-disable-next-line no-await-in-loop
42- const { md5 } = await pcs . upload ( piece , '' , 'overwrite' , 'tmpfile' ) as any ;
37+ const { md5 } = await pcs . upload ( piece , '' , 'overwrite' , 'tmpfile' ) ;
4338 blocks . push ( md5 ) ;
4439 }
4540 const param = {
4641 block_list : blocks ,
4742 } ;
48- return pcs . createSuperFile ( join ( remote , currentValue ) , param ) as unknown as Promise < void > ;
43+ await pcs . createSuperFile ( join ( remote , file ) , param ) ;
4944 }
50- console . log ( `${ chalk . blueBright ( '==>' ) } Uploading ${ currentValue } ` ) ;
51- return pcs . upload ( currentValue , join ( remote , currentValue ) ) as Promise < void > ;
52- } , Promise . resolve ( ) ) ;
53-
54- // todo
45+ console . log ( `${ chalk . blueBright ( '==>' ) } Uploading ${ file } ` ) ;
46+ await pcs . upload ( file , join ( remote , file ) ) ;
47+ }
5548 } catch ( err : any ) {
5649 const { response : { data } } = err ;
5750 console . log ( `error code ${ data . error_code } : ${ data . error_msg } ` ) ;
0 commit comments