Skip to content

Commit

Permalink
added support for list multiple Buckets/Upload parts
Browse files Browse the repository at this point in the history
  • Loading branch information
ebozduman committed Sep 29, 2020
1 parent c03dd72 commit fa82a87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/main/xml-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var parseXml = (xml) => {
export function parseError(xml, headerInfo) {
var xmlErr = {}
var xmlObj = fxp.parse(xml)
if (xmlObj['Error']) {
xmlErr = xmlObj['Error']
if (xmlObj.Error) {
xmlErr = xmlObj.Error
}

var e = new errors.S3Error()
Expand Down Expand Up @@ -76,7 +76,9 @@ export function parseListMultipart(xml) {
prefixes: [],
isTruncated: false
}
var xmlobj = parseXml(xml)

var xmlobj = parseXml(xml)

if (!xmlobj.ListMultipartUploadsResult) {
throw new errors.InvalidXMLError('Missing tag: "ListMultipartUploadsResult"')
}
Expand All @@ -87,13 +89,20 @@ export function parseListMultipart(xml) {
if (xmlobj.CommonPrefixes) xmlobj.CommonPrefixes.forEach(prefix => {
result.prefixes.push({prefix: prefix[0]})
})
if (xmlobj.Upload) (upload => {
result.uploads.push({
key: upload.Key,
uploadId: upload.UploadId[0],
initiated: new Date(upload.Initiated[0])
if (xmlobj.Upload) {
if (!Array.isArray(xmlobj.Upload)) {
xmlobj.Upload = Array(xmlobj.Upload)
}
xmlobj.Upload.forEach(upload => {
var key = upload.Key
var uploadId = upload.UploadId
var initiator = {id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName}
var owner = {id: upload.Owner.ID, displayName: upload.Owner.DisplayName}
var storageClass = upload.StorageClass
var initiated = new Date(upload.Initiated)
result.uploads.push({key, uploadId, initiator, owner, storageClass, initiated})
})
})
}
return result
}

Expand All @@ -105,11 +114,14 @@ export function parseListBucket(xml) {
if (!xmlobj.ListAllMyBucketsResult) {
throw new errors.InvalidXMLError('Missing tag: "ListAllMyBucketsResult"')
}
var allMyBuckets = xmlobj.ListAllMyBucketsResult
xmlobj = xmlobj.ListAllMyBucketsResult

if (allMyBuckets.Buckets) {
if (allMyBuckets.Buckets.Bucket) {
allMyBuckets.Buckets.Bucket.forEach(bucket => {
if (xmlobj.Buckets) {
if (xmlobj.Buckets.Bucket) {
if (!Array.isArray(xmlobj.Buckets.Bucket)) {
xmlobj.Buckets.Bucket = Array(xmlobj.Buckets.Bucket)
}
xmlobj.Buckets.Bucket.forEach(bucket => {
var name = bucket.Name
var creationDate = new Date(bucket.CreationDate)
result.push({name, creationDate})
Expand Down Expand Up @@ -261,7 +273,7 @@ export function parseListObjects(xml) {
var lastModified = new Date(content.LastModified)
var etag = content.ETag.replace(/^"/g, '').replace(/"$/g, '')
.replace(/^"/g, '').replace(/"$/g, '')
.replace(/^"/g, '').replace(/^"$/g, '')
.replace(/^"/g, '').replace(/"$/g, '')
var size = +content.Size
result.objects.push({name, lastModified, etag, size})
nextMarker = name
Expand Down
1 change: 1 addition & 0 deletions src/test/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ describe('functional tests', function() {
})

step(`listObjects(bucketName, prefix, recursive)_bucketName:${bucketName}, recursive:false_`, done => {
listArray = []
client.listObjects(bucketName, '', false)
.on('error', done)
.on('end', () => {
Expand Down

0 comments on commit fa82a87

Please sign in to comment.