From fd12add665720a025a7f2e6a76167f20c34d0e42 Mon Sep 17 00:00:00 2001 From: Panagiotis Kapros Date: Thu, 19 Dec 2024 20:16:10 +0200 Subject: [PATCH] fix missing Owner/Initiator GCS (#1369) --- src/internal/xml-parser.ts | 24 +++++++++++++++--------- tests/unit/test.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/internal/xml-parser.ts b/src/internal/xml-parser.ts index 99bc2c3b..1dcd703c 100644 --- a/src/internal/xml-parser.ts +++ b/src/internal/xml-parser.ts @@ -333,8 +333,8 @@ export type ListMultipartResult = { uploads: { key: string uploadId: UploadID - initiator: unknown - owner: unknown + initiator?: { id: string; displayName: string } + owner?: { id: string; displayName: string } storageClass: unknown initiated: Date }[] @@ -381,13 +381,19 @@ export function parseListMultipart(xml: string): ListMultipartResult { if (xmlobj.Upload) { toArray(xmlobj.Upload).forEach((upload) => { - const key = upload.Key - const uploadId = upload.UploadId - const initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName } - const owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName } - const storageClass = upload.StorageClass - const initiated = new Date(upload.Initiated) - result.uploads.push({ key, uploadId, initiator, owner, storageClass, initiated }) + const uploadItem: ListMultipartResult['uploads'][number] = { + key: upload.Key, + uploadId: upload.UploadId, + storageClass: upload.StorageClass, + initiated: new Date(upload.Initiated), + } + if (upload.Initiator) { + uploadItem.initiator = { id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName } + } + if (upload.Owner) { + uploadItem.owner = { id: upload.Owner.ID, displayName: upload.Owner.DisplayName } + } + result.uploads.push(uploadItem) }) } return result diff --git a/tests/unit/test.js b/tests/unit/test.js index 72e559b8..8d1175ef 100644 --- a/tests/unit/test.js +++ b/tests/unit/test.js @@ -32,7 +32,7 @@ import { partsRequired, } from '../../src/internal/helper.ts' import { joinHostPort } from '../../src/internal/join-host-port.ts' -import { parseListObjects } from '../../src/internal/xml-parser.ts' +import { parseListMultipart, parseListObjects } from '../../src/internal/xml-parser.ts' import * as Minio from '../../src/minio.js' const Package = { version: 'development' } @@ -2304,6 +2304,39 @@ describe('xml-parser', () => { }) }) }) + + describe('#listMultipart()', () => { + describe('should handle missing owner and initiator', () => { + // example response from GCS + const xml = ` + + + some-bucket + + + + some-file.pdf + / + + 1000 + false + + some-file.pdf + ABPnzm4aGoV3sjevTkVeaWV6lvBFtdjcZegTJg8MUfTue1t6lgRIy6_JEoM0km3CNE218x00 + STANDARD + 2024-12-17T08:16:52.396303Z + + + ` + + it('should parse list incomplete', () => { + const { uploads } = parseListMultipart(xml) + assert.equal(uploads.length, 1) + assert.equal(uploads[0].key, 'some-file.pdf') + }) + }) + }) }) describe('join-host-port', () => {