@@ -264,26 +264,37 @@ function processMasterVersions(bucketName, listParams, list) {
264264
265265function processOptionalAttributes ( item , optionalAttributes ) {
266266 const xml = [ ] ;
267-
268- for ( const key of Object . keys ( item ) ) {
269- if ( key . startsWith ( 'x-amz-meta-' ) ) {
270- if ( optionalAttributes . includes ( 'x-amz-meta-*' ) || optionalAttributes . includes ( key ) ) {
271- xml . push ( `<${ key } >${ item [ key ] } </${ key } >` ) ;
272- }
267+ const userMetadata = new Set ( ) ;
268+
269+ for ( const attribute of optionalAttributes ) {
270+ switch ( attribute ) {
271+ case 'RestoreStatus' :
272+ xml . push ( '<RestoreStatus>' ) ;
273+ xml . push ( `<IsRestoreInProgress>${ ! ! item . restoreStatus ?. inProgress } </IsRestoreInProgress>` ) ;
274+
275+ if ( item . restoreStatus ?. expiryDate ) {
276+ xml . push ( `<RestoreExpiryDate>${ item . restoreStatus ?. expiryDate } </RestoreExpiryDate>` ) ;
277+ }
278+
279+ xml . push ( '</RestoreStatus>' ) ;
280+ break ;
281+ case 'x-amz-meta-*' :
282+ for ( const key of Object . keys ( item . userMetadata ) ) {
283+ userMetadata . add ( key ) ;
284+ }
285+ break ;
286+ default :
287+ if ( item . userMetadata ?. [ attribute ] ) {
288+ userMetadata . add ( attribute ) ;
289+ }
273290 }
274291 }
275292
276- if ( optionalAttributes . includes ( 'RestoreStatus' ) ) {
277- xml . push ( '<RestoreStatus>' ) ;
278- xml . push ( `<IsRestoreInProgress>${ ! ! item . restoreStatus ?. inProgress } </IsRestoreInProgress>` ) ;
279-
280- if ( item . restoreStatus ?. expiryDate ) {
281- xml . push ( `<RestoreExpiryDate>${ item . restoreStatus ?. expiryDate } </RestoreExpiryDate>` ) ;
282- }
283-
284- xml . push ( '</RestoreStatus>' ) ;
293+ for ( const key of userMetadata ) {
294+ xml . push ( `<${ key } >${ item . userMetadata [ key ] } </${ key } >` ) ;
285295 }
286296
297+
287298 return xml ;
288299}
289300
0 commit comments