Skip to content

Commit

Permalink
v0.5.9 修复 getObject 内容会被解析成 xml 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jan 25, 2019
1 parent 9db8ccf commit 6c76e75
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.8';
COS.version = '0.5.9';

module.exports = COS;

Expand Down Expand Up @@ -6212,7 +6212,7 @@ function _submitRequest(params, callback) {

var jsonRes;
try {
jsonRes = util.xml2json(body) || {};
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "0.5.8",
"version": "0.5.9",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion server/sts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'durationSeconds' => 1800, // 密钥有效期
'allowPrefix' => '*', // 必填,这里改成允许的路径前缀,这里可以根据自己网站的用户登录态判断允许上传的目录,例子:* 或者 a/* 或者 a.jpg
// 密钥的权限列表
'allowActions' => array (
'allowActions' => array(
// 所有 action 请看文档 https://cloud.tencent.com/document/product/436/31923
// 简单上传
'name/cos:PutObject',
Expand Down
2 changes: 1 addition & 1 deletion src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ function _submitRequest(params, callback) {

var jsonRes;
try {
jsonRes = util.xml2json(body) || {};
jsonRes = body && body.indexOf('<') > -1 && body.indexOf('>') > -1 && util.xml2json(body) || {};
} catch (e) {
jsonRes = body || {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.8';
COS.version = '0.5.9';

module.exports = COS;
60 changes: 31 additions & 29 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,20 +1295,21 @@ group('ObjectAcl', function () {
});
});
});
test('putObjectAcl() header ACL:public-read-write', function (done, assert) {
cos.putObjectAcl({
Bucket: config.Bucket,
Region: config.Region,
ACL: 'public-read-write',
Key: '1.txt',
}, function (err, data) {
assert.ok(!err, 'putObjectAcl 成功');
cos.getObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.txt'}, function (err, data) {
assert.ok(data.ACL = 'public-read-write');
done();
});
});
});
// Object 不再支持修改写权限
// test('putObjectAcl() header ACL:public-read-write', function (done, assert) {
// cos.putObjectAcl({
// Bucket: config.Bucket,
// Region: config.Region,
// ACL: 'public-read-write',
// Key: '1.txt',
// }, function (err, data) {
// assert.ok(!err, 'putObjectAcl 成功');
// cos.getObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.txt'}, function (err, data) {
// assert.ok(data.ACL = 'public-read-write');
// done();
// });
// });
// });
test('putObjectAcl() header GrantRead:1001,1002', function (done, assert) {
var GrantRead = 'id="qcs::cam::uin/1001:uin/1001",id="qcs::cam::uin/1002:uin/1002"';
cos.putObjectAcl({
Expand All @@ -1324,21 +1325,22 @@ group('ObjectAcl', function () {
});
});
});
test('putObjectAcl() header GrantWrite:1001,1002', function (done, assert) {
var GrantWrite = 'id="qcs::cam::uin/1001:uin/1001", id="qcs::cam::uin/1002:uin/1002"';
cos.putObjectAcl({
Bucket: config.Bucket,
Region: config.Region,
GrantWrite: GrantWrite,
Key: '1.txt',
}, function (err, data) {
assert.ok(!err, 'putObjectAcl 成功');
cos.getObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.txt'}, function (err, data) {
assert.ok(data.GrantWrite = GrantWrite);
done();
});
});
});
// Object 不再支持修改写权限
// test('putObjectAcl() header GrantWrite:1001,1002', function (done, assert) {
// var GrantWrite = 'id="qcs::cam::uin/1001:uin/1001", id="qcs::cam::uin/1002:uin/1002"';
// cos.putObjectAcl({
// Bucket: config.Bucket,
// Region: config.Region,
// GrantWrite: GrantWrite,
// Key: '1.txt',
// }, function (err, data) {
// assert.ok(!err, 'putObjectAcl 成功');
// cos.getObjectAcl({Bucket: config.Bucket, Region: config.Region, Key: '1.txt'}, function (err, data) {
// assert.ok(data.GrantWrite = GrantWrite);
// done();
// });
// });
// });
test('putObjectAcl() header GrantFullControl:1001,1002', function (done, assert) {
var GrantFullControl = 'id="qcs::cam::uin/1001:uin/1001", id="qcs::cam::uin/1002:uin/1002"';
cos.putObjectAcl({
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var replaceDevCode = function (list) {
newContent = newContent.replace(/AKID\w+/, 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
newContent = newContent.replace(/'secretKey' => '[^']+',/, "'secretKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',");
newContent = newContent.replace(/secretKey: '[^']+',/, "secretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',");
newContent = newContent.replace("array ('name/cos:*')", `array (
newContent = newContent.replace(/'allowActions' *=> *array\([^)]+\)/, `'allowActions' => array(
// 所有 action 请看文档 https://cloud.tencent.com/document/product/436/31923
// 简单上传
'name/cos:PutObject',
// 分片上传
Expand Down

0 comments on commit 6c76e75

Please sign in to comment.