diff --git a/lib/common/object/getBucketVersions.js b/lib/common/object/getBucketVersions.js index d497278ea..7ac826018 100644 --- a/lib/common/object/getBucketVersions.js +++ b/lib/common/object/getBucketVersions.js @@ -1,6 +1,7 @@ /* eslint-disable no-use-before-define */ const proto = exports; const isObject = require('../utils/isObject'); +const isArray = require('../utils/isArray'); proto.getBucketVersions = getBucketVersions; @@ -47,7 +48,7 @@ async function getBucketVersions(query = {}, options = {}) { })); } if (deleteMarker) { - if (!Array.isArray(deleteMarker)) { + if (!isArray(deleteMarker)) { deleteMarker = [deleteMarker]; } deleteMarker = deleteMarker.map(obj => ({ @@ -60,10 +61,18 @@ async function getBucketVersions(query = {}, options = {}) { } })); } + let prefixes = result.data.CommonPrefixes || null; + if (prefixes) { + if (!isArray(prefixes)) { + prefixes = [prefixes]; + } + prefixes = prefixes.map(item => item.Prefix); + } return { res: result.res, objects, deleteMarker, + prefixes, nextMarker: result.data.NextMarker || null, NextVersionIdMarker: result.data.NextVersionIdMarker || null, isTruncated: result.data.IsTruncated === 'true' diff --git a/test/node/multiversion.test.js b/test/node/multiversion.test.js index a0d092818..6983ce398 100644 --- a/test/node/multiversion.test.js +++ b/test/node/multiversion.test.js @@ -89,6 +89,18 @@ describe('test/multiversion.test.js', () => { assert(false, err.message); } }); + it('should getBucketVersions with delimiter', async () => { + const names = ['getBucketVersions/delimiter1.js', 'getBucketVersions/delimiter2.js', 'getBucketVersions/delimiter3.js', 'others.js']; + await Promise.all(names.map(_name => store.put(_name, __filename))); + try { + const result = await store.getBucketVersions({ + delimiter: '/' + }); + assert(result.prefixes && result.prefixes.includes('getBucketVersions/')); + } catch (err) { + assert(false, err.message); + } + }); }); describe('putBucketLifecycle() getBucketLifecycle()', () => {