diff --git a/lib/common/bucket/dataIndex.js b/lib/common/bucket/dataIndex.js index 9e07a1d2..6786bf6c 100644 --- a/lib/common/bucket/dataIndex.js +++ b/lib/common/bucket/dataIndex.js @@ -68,21 +68,36 @@ async function doMetaQuery(bucketName, queryParam, options = {}) { params.content = obj2xml_1.obj2xml(paramXMLObj, { headers: true, firstUpperCase: true }); const result = await this.request(params); const { NextToken, Files, Aggregations: aggRes } = await this.parseXML(result.data); + // console.log('Files', JSON.stringify(Files)); let files = []; if (Files && Files.File) { const getFileObject = item => { - const ossTagging = item.OSSTagging - ? item.OSSTagging.map(tagging => ({ + let ossTagging = []; + const { OSSTagging } = item; + if (OSSTagging && OSSTagging.Tagging) { + const { Tagging } = OSSTagging; + if (Tagging instanceof Array) { + ossTagging = Tagging.map(tagging => ({ key: tagging.Key, value: tagging.Value - })) - : []; - const ossUserMeta = item.OSSUserMeta - ? item.OSSUserMeta.map(meta => ({ + })); + } else if (Tagging instanceof Object) { + ossTagging = [{ key: Tagging.Key, vlaue: Tagging.Value }]; + } + } + let ossUserMeta = []; + const { OSSUserMeta } = item; + if (OSSUserMeta && OSSUserMeta.UserMeta) { + const { UserMeta } = OSSUserMeta; + if (UserMeta instanceof Array) { + ossUserMeta = UserMeta.map(meta => ({ key: meta.Key, value: meta.Value - })) - : []; + })); + } else if (UserMeta instanceof Object) { + ossUserMeta = [{ key: UserMeta.Key, vlaue: UserMeta.Value }]; + } + } return { fileName: item.Filename, size: item.Size, @@ -91,7 +106,7 @@ async function doMetaQuery(bucketName, queryParam, options = {}) { ossStorageClass: item.OSSStorageClass, objectACL: item.ObjectACL, eTag: item.ETag, - ossTaggingCount: item.OSSTaggingCount, + ossTaggingCount: item.OSSTaggingCount || 0, ossTagging, ossUserMeta, ossCRC64: item.OSSCRC64, diff --git a/lib/common/bucket/dataIndex.ts b/lib/common/bucket/dataIndex.ts index 9c072d55..65e3ffc2 100644 --- a/lib/common/bucket/dataIndex.ts +++ b/lib/common/bucket/dataIndex.ts @@ -107,22 +107,38 @@ export async function doMetaQuery(this: any, bucketName: string, queryParam: IMe const result = await this.request(params); const { NextToken, Files, Aggregations: aggRes } = await this.parseXML(result.data); - + // console.log('Files', JSON.stringify(Files)); let files: any[] = []; if (Files && Files.File) { const getFileObject = item => { - const ossTagging = item.OSSTagging - ? item.OSSTagging.map(tagging => ({ + let ossTagging: any[] = []; + const { OSSTagging } = item; + if (OSSTagging && OSSTagging.Tagging) { + const { Tagging } = OSSTagging; + if (Tagging instanceof Array) { + ossTagging = Tagging.map(tagging => ({ key: tagging.Key, value: tagging.Value - })) - : []; - const ossUserMeta = item.OSSUserMeta - ? item.OSSUserMeta.map(meta => ({ + })); + } else if (Tagging instanceof Object) { + ossTagging = [{ key: Tagging.Key, vlaue: Tagging.Value }]; + } + } + + let ossUserMeta: any[] = []; + const { OSSUserMeta } = item; + if (OSSUserMeta && OSSUserMeta.UserMeta) { + const { UserMeta } = OSSUserMeta; + if (UserMeta instanceof Array) { + ossUserMeta = UserMeta.map(meta => ({ key: meta.Key, value: meta.Value - })) - : []; + })); + } else if (UserMeta instanceof Object) { + ossUserMeta = [{ key: UserMeta.Key, vlaue: UserMeta.Value }]; + } + } + return { fileName: item.Filename, size: item.Size, @@ -131,7 +147,7 @@ export async function doMetaQuery(this: any, bucketName: string, queryParam: IMe ossStorageClass: item.OSSStorageClass, objectACL: item.ObjectACL, eTag: item.ETag, - ossTaggingCount: item.OSSTaggingCount, + ossTaggingCount: item.OSSTaggingCount || 0, ossTagging, ossUserMeta, ossCRC64: item.OSSCRC64, diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 79c2f8e7..076703f7 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -18,10 +18,10 @@ describe('test/bucket.test.js', () => { [ { authorizationV4: false - }, - { - authorizationV4: true } + // { + // authorizationV4: true + // } ].forEach((moreConfigs, idx) => { describe(`test bucket in iterate ${idx}`, () => { before(async () => { @@ -1680,11 +1680,42 @@ describe('test/bucket.test.js', () => { assert(result.aggregations[1].field, 'OSSTaggingCount'); }); - it('closeMetaQuery()', async () => { - const result = await store.closeMetaQuery(sts.bucket); + it.only('doMetaQuery() three Aggregations', async () => { + const queryParam = { + maxResults: 12, + query: { + operation: 'and', + subQueries: [ + // { field: 'Filename', value: 'test-', operation: 'match' }, + { field: 'Size', value: '3111', operation: 'gt' } + ] + }, + aggregations: [ + // { field: 'ETag', operation: 'count' } + // { field: 'FileModifiedTime', operation: 'distinct' }, + // { field: 'Filename', operation: 'group' }, + // { field: 'ObjectACL', operation: 'group' }, + // { field: 'OSSCRC64', operation: 'distinct' }, + // { field: 'OSSStorageClass', operation: 'group' }, + // { field: 'OSSTaggingCount', operation: 'max' }, + // { field: 'ServerSideEncryption', operation: 'group' }, + // { field: 'Size', operation: 'sum' } + ] + }; + + const result = await store.doMetaQuery(sts.bucket, queryParam); + console.log('result::', result.aggregations, result.files); // result.res.data.toString(), assert.strictEqual(result.status, 200); - await utils.sleep(sleepTime * 2); + // assert(result.aggregations.length > 0); + // assert(result.aggregations[0].field, 'Size'); + // assert(result.aggregations[1].field, 'OSSTaggingCount'); }); + + // it('closeMetaQuery()', async () => { + // const result = await store.closeMetaQuery(sts.bucket); + // assert.strictEqual(result.status, 200); + // await utils.sleep(sleepTime * 2); + // }); }); }); });