@@ -64,12 +64,12 @@ function parse_copy_source(req) {
6464async function list_objects ( params , account_name , container , sasToken ) {
6565
6666 const hostname = `${ account_name } .blob.core.windows.net` ;
67- const delimiter = params . delimiter || '/' ;
68- const maxResults = params . limit === 0 ? 1 : params . limit ;
6967
70- let path = `https://${ account_name } .blob.core.windows.net/${ container } ?restype=container&comp=list&delimiter= ${ delimiter } ` +
71- `&maxresults=${ maxResults } &${ sasToken } ` ;
68+ let path = `https://${ account_name } .blob.core.windows.net/${ container } ?restype=container&comp=list` +
69+ `&maxresults=${ params . limit } &${ sasToken } ` ;
7270 if ( params . key_marker ) path += `&marker=${ params . key_marker } ` ;
71+ if ( params . delimiter ) path += `&delimiter=${ params . delimiter } ` ;
72+ if ( params . prefix ) path += `&prefix=${ params . prefix } ` ;
7373
7474 let response ;
7575 try {
@@ -80,15 +80,24 @@ async function list_objects(params, account_name, container, sasToken) {
8080 const status_code = response . statusCode ;
8181 const buffer = await read_stream_join ( response ) ;
8282 const body = buffer . toString ( 'utf8' ) ;
83- if ( status_code !== 200 ) {
84- throw new Error ( `Could not get blobs and diresctories list, (status code: ${ status_code } ) got ${ body } ` ) ;
85- }
8683
8784 let blobs ;
8885 let dirs ;
8986 let next_marker ;
9087 try {
9188 const parsed = await parse_xml_to_js ( body ) ;
89+ if ( status_code !== 200 ) {
90+ if ( parsed . Error ) {
91+ const code = parsed . Error . Code && parsed . Error . Code [ 0 ] ;
92+ const faulty_query_param = parsed . Error . QueryParameterName &&
93+ parsed . Error . QueryParameterName [ 0 ] ;
94+ if ( code === 'OutOfRangeQueryParameterValue' &&
95+ faulty_query_param === 'maxresults' && params . limit === 0 ) {
96+ return { blobs : [ ] , dirs : [ ] , next_marker : '' } ;
97+ }
98+ }
99+ throw new Error ( `Could not get blobs and diresctories list, (status code: ${ status_code } ) got ${ body } ` ) ;
100+ }
92101 blobs = parsed . EnumerationResults . Blobs [ 0 ] . Blob ;
93102 dirs = parsed . EnumerationResults . Blobs [ 0 ] . BlobPrefix ;
94103 next_marker = parsed . EnumerationResults . NextMarker [ 0 ] ;
0 commit comments