From 7d26c4233037c8cbf84e6fedb08de0e92a07b01c Mon Sep 17 00:00:00 2001 From: chrisftian Date: Tue, 2 Apr 2024 14:24:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20getService=20=E5=AF=B9=E9=BD=90=20api?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/demo.js | 13 ++++++++----- index.d.ts | 12 ++++++++++++ package.json | 2 +- sdk/base.js | 8 ++++++++ test/test.js | 25 +++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 910ad1d..45eafe0 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -91,11 +91,14 @@ function getObjectUrl() { } function getService() { - cos.getService( - { - Region: 'ap-guangzhou', - }, - function (err, data) { + cos.getService({ + // Region: 'ap-beijing', + CreateRange: 'lt', + CreateTime: 1642662645, + // TagKey: 'k1', + // TagValue: 'v1', + MaxKeys: 20, + }, function (err, data) { console.log(err || data); } ); diff --git a/index.d.ts b/index.d.ts index 0b440a4..62d11b3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -351,6 +351,18 @@ declare namespace COS { Region?: Region; /** 发请求时带上的 Header 字段 */ Headers?: Headers; + /** 传入标签键 */ + TagKey?: string; + /** 传入标签值 */ + TagValue?: string; + /** GMT 时间戳,和 CreateRange 参数一起使用,支持根据创建时间过滤存储桶 */ + CreateTime?: number; + /** 和 CreateTime 参数一起使用,支持根据创建时间过滤存储桶 */ + CreateRange?: 'lt' | 'gt' | 'lte' | 'gte' | string; + /** 起始标记,从该标记之后(不含)按照 UTF-8 字典序返回存储桶条目 */ + Marker?: string; + /** 单次返回最大的条目数量,默认值为2000,最大为2000 */ + MaxKeys?: number; } /** getService 接口返回值 */ interface GetServiceResult extends GeneralResult { diff --git a/package.json b/package.json index 2a82694..dbcf284 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cos-nodejs-sdk-v5", - "version": "2.13.3", + "version": "2.13.4", "description": "cos nodejs sdk v5", "main": "index.js", "types": "index.d.ts", diff --git a/sdk/base.js b/sdk/base.js index 6462f6b..576382a 100644 --- a/sdk/base.js +++ b/sdk/base.js @@ -52,6 +52,14 @@ function getService(params, callback) { method: 'GET', headers: params.Headers, SignHost: SignHost, + qs: { + tagkey: params.TagKey, + tagvalue: params.TagValue, + 'create-time': params.CreateTime, + range: params.CreateRange, + marker: params.Marker, + 'max-keys': params.MaxKeys, + }, }, function (err, data) { if (err) return callback(err); diff --git a/test/test.js b/test/test.js index 78c2fff..cd7cfb0 100644 --- a/test/test.js +++ b/test/test.js @@ -393,6 +393,31 @@ group('getService()', function () { }) .catch(function () {}); }); + test('能正常列出 Bucket 多参数', function (done, assert) { + prepareBucket() + .then(function () { + cos.getService( + { + Region: config.Region, + CreateRange: 'gt', + CreateTime: 1642662645, + MaxKeys: 2000, + }, + function (err, data) { + var hasBucket = false; + data.Buckets && + data.Buckets.forEach(function (item) { + if (item.Name === BucketLongName && (item.Location === config.Region || !item.Location)) { + hasBucket = true; + } + }); + assert.ok(hasBucket); + done(); + } + ); + }) + .catch(function () {}); + }); }); group('putBucket()', function () {