Skip to content

Commit

Permalink
feat: getService 对齐 api 参数 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
livehigh committed Apr 2, 2024
1 parent dc5251e commit 7d26c42
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
13 changes: 8 additions & 5 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
Expand Down
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions sdk/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 7d26c42

Please sign in to comment.