From 390b4492bd130c08e58c3a1abbd280c4678d7d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E8=8B=A5=E9=9C=9C=E5=AF=92?= <912881342@qq.com> Date: Tue, 2 Jun 2020 17:14:02 +0800 Subject: [PATCH] fix: getBucketVersions result has no prefixes (#799) --- lib/common/object/getBucketVersions.js | 11 ++++++++++- test/node/multiversion.test.js | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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()', () => {