@@ -8,14 +8,9 @@ const escapeForXml = s3middleware.escapeForXml;
88const { pushMetric } = require ( '../utapi/utilities' ) ;
99const versionIdUtils = versioning . VersionID ;
1010const monitoring = require ( '../utilities/monitoringHandler' ) ;
11- const { generateToken, decryptToken }
12- = require ( '../api/apiUtils/object/continueToken' ) ;
11+ const { generateToken, decryptToken } = require ( '../api/apiUtils/object/continueToken' ) ;
1312
14- // do not url encode the continuation tokens
15- const skipUrlEncoding = new Set ( [
16- 'ContinuationToken' ,
17- 'NextContinuationToken' ,
18- ] ) ;
13+ const xmlParamsToSkipUrlEncoding = new Set ( [ 'ContinuationToken' , 'NextContinuationToken' ] ) ;
1914
2015/* Sample XML response for GET bucket objects V2:
2116<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@@ -122,17 +117,16 @@ function processVersions(bucketName, listParams, list) {
122117 { tag : 'IsTruncated' , value : isTruncated } ,
123118 ] ;
124119
125- const escapeXmlFn = listParams . encoding === 'url' ?
126- querystring . escape : escapeForXml ;
120+ const escapeXmlFn = listParams . encoding === 'url' ? querystring . escape : escapeForXml ;
127121 xmlParams . forEach ( p => {
128122 if ( p . value ) {
129123 const val = p . tag !== 'NextVersionIdMarker' || p . value === 'null' ?
130- p . value : versionIdUtils . encode ( p . value ) ;
124+ p . value :
125+ versionIdUtils . encode ( p . value ) ;
131126 xml . push ( `<${ p . tag } >${ escapeXmlFn ( val ) } </${ p . tag } >` ) ;
132127 }
133128 } ) ;
134- let lastKey = listParams . keyMarker ?
135- escapeXmlFn ( listParams . keyMarker ) : undefined ;
129+ let lastKey = listParams . keyMarker ? escapeXmlFn ( listParams . keyMarker ) : undefined ;
136130 list . Versions . forEach ( item => {
137131 const v = item . value ;
138132 const objectKey = escapeXmlFn ( item . key ) ;
@@ -143,7 +137,8 @@ function processVersions(bucketName, listParams, list) {
143137 `<Key>${ objectKey } </Key>` ,
144138 '<VersionId>' ,
145139 ( v . IsNull || v . VersionId === undefined ) ?
146- 'null' : versionIdUtils . encode ( v . VersionId ) ,
140+ 'null'
141+ : versionIdUtils . encode ( v . VersionId ) ,
147142 '</VersionId>' ,
148143 `<IsLatest>${ isLatest } </IsLatest>` ,
149144 `<LastModified>${ v . LastModified } </LastModified>` ,
@@ -182,31 +177,19 @@ function processMasterVersions(bucketName, listParams, list) {
182177 ] ;
183178
184179 if ( listParams . v2 ) {
185- xmlParams . push (
186- { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
187- xmlParams . push (
188- { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
189- xmlParams . push ( {
190- tag : 'ContinuationToken' ,
191- value : generateToken ( listParams . continuationToken ) || '' ,
192- } ) ;
193- xmlParams . push ( {
194- tag : 'NextContinuationToken' ,
195- value : generateToken ( list . NextContinuationToken ) ,
196- } ) ;
197- xmlParams . push ( {
198- tag : 'KeyCount' ,
199- value : list . Contents ? list . Contents . length : 0 ,
200- } ) ;
180+ xmlParams . push ( { tag : 'StartAfter' , value : listParams . startAfter || '' } ) ;
181+ xmlParams . push ( { tag : 'FetchOwner' , value : `${ listParams . fetchOwner } ` } ) ;
182+ xmlParams . push ( { tag : 'ContinuationToken' , value : generateToken ( listParams . continuationToken ) || '' , } ) ;
183+ xmlParams . push ( { tag : 'NextContinuationToken' , value : generateToken ( list . NextContinuationToken ) , } ) ;
184+ xmlParams . push ( { tag : 'KeyCount' , value : list . Contents ? list . Contents . length : 0 , } ) ;
201185 } else {
202186 xmlParams . push ( { tag : 'Marker' , value : listParams . marker || '' } ) ;
203187 xmlParams . push ( { tag : 'NextMarker' , value : list . NextMarker } ) ;
204188 }
205189
206- const escapeXmlFn = listParams . encoding === 'url' ?
207- querystring . escape : escapeForXml ;
190+ const escapeXmlFn = listParams . encoding === 'url' ? querystring . escape : escapeForXml ;
208191 xmlParams . forEach ( p => {
209- if ( p . value && skipUrlEncoding . has ( p . tag ) ) {
192+ if ( p . value && xmlParamsToSkipUrlEncoding . has ( p . tag ) ) {
210193 xml . push ( `<${ p . tag } >${ p . value } </${ p . tag } >` ) ;
211194 } else if ( p . value || p . tag === 'KeyCount' || p . tag === 'MaxKeys' ) {
212195 xml . push ( `<${ p . tag } >${ escapeXmlFn ( p . value ) } </${ p . tag } >` ) ;
@@ -246,10 +229,10 @@ function processMasterVersions(bucketName, listParams, list) {
246229 ) ;
247230 } ) ;
248231 list . CommonPrefixes . forEach ( item => {
249- const val = escapeXmlFn ( item ) ;
250- xml . push ( `<CommonPrefixes><Prefix>${ val } </Prefix></CommonPrefixes>` ) ;
232+ xml . push ( `<CommonPrefixes><Prefix>${ escapeXmlFn ( item ) } </Prefix></CommonPrefixes>` ) ;
251233 } ) ;
252234 xml . push ( '</ListBucketResult>' ) ;
235+
253236 return xml . join ( '' ) ;
254237}
255238
@@ -298,17 +281,13 @@ function bucketGet(authInfo, request, log, callback) {
298281 'List Type specified in Request' ) ) ;
299282 }
300283 if ( v2 ) {
301- log . addDefaultFields ( {
302- action : 'ListObjectsV2' ,
303- } ) ;
284+ log . addDefaultFields ( { action : 'ListObjectsV2' , } ) ;
304285 if ( request . serverAccessLog ) {
305286 // eslint-disable-next-line no-param-reassign
306287 request . serverAccessLog . analyticsAction = 'ListObjectsV2' ;
307288 }
308289 } else if ( params . versions !== undefined ) {
309- log . addDefaultFields ( {
310- action : 'ListObjectVersions' ,
311- } ) ;
290+ log . addDefaultFields ( { action : 'ListObjectVersions' , } ) ;
312291 if ( request . serverAccessLog ) {
313292 // eslint-disable-next-line no-param-reassign
314293 request . serverAccessLog . analyticsAction = 'ListObjectVersions' ;
@@ -317,16 +296,14 @@ function bucketGet(authInfo, request, log, callback) {
317296 log . debug ( 'processing request' , { method : 'bucketGet' } ) ;
318297 const encoding = params [ 'encoding-type' ] ;
319298 if ( encoding !== undefined && encoding !== 'url' ) {
320- monitoring . promMetrics (
321- 'GET' , bucketName , 400 , 'listBucket' ) ;
299+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
322300 return callback ( errorInstances . InvalidArgument . customizeDescription ( 'Invalid ' +
323301 'Encoding Method specified in Request' ) ) ;
324302 }
325- const requestMaxKeys = params [ 'max-keys' ] ?
326- Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
303+
304+ const requestMaxKeys = params [ 'max-keys' ] ? Number . parseInt ( params [ 'max-keys' ] , 10 ) : 1000 ;
327305 if ( Number . isNaN ( requestMaxKeys ) || requestMaxKeys < 0 ) {
328- monitoring . promMetrics (
329- 'GET' , bucketName , 400 , 'listBucket' ) ;
306+ monitoring . promMetrics ( 'GET' , bucketName , 400 , 'listBucket' ) ;
330307 return callback ( errors . InvalidArgument ) ;
331308 }
332309 // AWS only returns 1000 keys even if max keys are greater.
@@ -353,8 +330,7 @@ function bucketGet(authInfo, request, log, callback) {
353330 if ( v2 ) {
354331 listParams . v2 = true ;
355332 listParams . startAfter = params [ 'start-after' ] ;
356- listParams . continuationToken =
357- decryptToken ( params [ 'continuation-token' ] ) ;
333+ listParams . continuationToken = decryptToken ( params [ 'continuation-token' ] ) ;
358334 listParams . fetchOwner = params [ 'fetch-owner' ] === 'true' ;
359335 } else {
360336 listParams . marker = params . marker ;
@@ -374,7 +350,8 @@ function bucketGet(authInfo, request, log, callback) {
374350 delete listParams . marker ;
375351 listParams . keyMarker = params [ 'key-marker' ] ;
376352 listParams . versionIdMarker = params [ 'version-id-marker' ] ?
377- versionIdUtils . decode ( params [ 'version-id-marker' ] ) : undefined ;
353+ versionIdUtils . decode ( params [ 'version-id-marker' ] ) :
354+ undefined ;
378355 }
379356
380357 if ( ! requestMaxKeys ) {
0 commit comments