Skip to content

Commit bdd9db9

Browse files
committed
fix missing Owner/Initiator GCS
1 parent c6f3565 commit bdd9db9

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/internal/xml-parser.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ export type ListMultipartResult = {
333333
uploads: {
334334
key: string
335335
uploadId: UploadID
336-
initiator: unknown
337-
owner: unknown
336+
initiator?: { id: string; displayName: string }
337+
owner?: { id: string; displayName: string }
338338
storageClass: unknown
339339
initiated: Date
340340
}[]
@@ -381,13 +381,19 @@ export function parseListMultipart(xml: string): ListMultipartResult {
381381

382382
if (xmlobj.Upload) {
383383
toArray(xmlobj.Upload).forEach((upload) => {
384-
const key = upload.Key
385-
const uploadId = upload.UploadId
386-
const initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName }
387-
const owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName }
388-
const storageClass = upload.StorageClass
389-
const initiated = new Date(upload.Initiated)
390-
result.uploads.push({ key, uploadId, initiator, owner, storageClass, initiated })
384+
const uploadItem: ListMultipartResult['uploads'][number] = {
385+
key: upload.Key,
386+
uploadId: upload.UploadId,
387+
storageClass: upload.StorageClass,
388+
initiated: new Date(upload.Initiated),
389+
}
390+
if (upload.Initiator) {
391+
uploadItem.initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName }
392+
}
393+
if (upload.Owner) {
394+
uploadItem.owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName }
395+
}
396+
result.uploads.push(uploadItem)
391397
})
392398
}
393399
return result

tests/unit/test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
partsRequired,
3333
} from '../../src/internal/helper.ts'
3434
import { joinHostPort } from '../../src/internal/join-host-port.ts'
35-
import { parseListObjects } from '../../src/internal/xml-parser.ts'
35+
import { parseListMultipart, parseListObjects } from '../../src/internal/xml-parser.ts'
3636
import * as Minio from '../../src/minio.js'
3737

3838
const Package = { version: 'development' }
@@ -2304,6 +2304,39 @@ describe('xml-parser', () => {
23042304
})
23052305
})
23062306
})
2307+
2308+
describe('#listMultipart()', () => {
2309+
describe('should handle missing owner and initiator', () => {
2310+
// example response from GCS
2311+
const xml = `
2312+
<?xml version='1.0' encoding='UTF-8'?>
2313+
<ListMultipartUploadsResult
2314+
xmlns='http://s3.amazonaws.com/doc/2006-03-01/'>
2315+
<Bucket>some-bucket</Bucket>
2316+
<KeyMarker></KeyMarker>
2317+
<UploadIdMarker></UploadIdMarker>
2318+
<NextKeyMarker></NextKeyMarker>
2319+
<Prefix>some-file.pdf</Prefix>
2320+
<Delimiter>/</Delimiter>
2321+
<NextUploadIdMarker></NextUploadIdMarker>
2322+
<MaxUploads>1000</MaxUploads>
2323+
<IsTruncated>false</IsTruncated>
2324+
<Upload>
2325+
<Key>some-file.pdf</Key>
2326+
<UploadId>ABPnzm4aGoV3sjevTkVeaWV6lvBFtdjcZegTJg8MUfTue1t6lgRIy6_JEoM0km3CNE218x00</UploadId>
2327+
<StorageClass>STANDARD</StorageClass>
2328+
<Initiated>2024-12-17T08:16:52.396303Z</Initiated>
2329+
</Upload>
2330+
</ListMultipartUploadsResult>
2331+
`
2332+
2333+
it('should parse list incomplete', () => {
2334+
const { uploads } = parseListMultipart(xml)
2335+
assert.equal(uploads.length, 1)
2336+
assert.equal(uploads[0].key, 'some-file.pdf')
2337+
})
2338+
})
2339+
})
23072340
})
23082341

23092342
describe('join-host-port', () => {

0 commit comments

Comments
 (0)