Skip to content

Commit

Permalink
修复getBucketReferer已知错误;支持mimeLimit、trafficLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
livehigh committed Nov 11, 2021
1 parent 9eca5ee commit 91d23d7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
18 changes: 14 additions & 4 deletions demo-album/lib/cos-wx-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.0.11';
COS.version = '1.0.12';

module.exports = COS;

Expand Down Expand Up @@ -6432,9 +6432,8 @@ function getBucketReferer(params, callback) {

var RefererConfiguration = data.RefererConfiguration || {};
if (RefererConfiguration['DomainList']) {
var Domains = util.clone(RefererConfiguration['DomainList'].Domain || []);
Domains = util.makeArray(Domains);
RefererConfiguration.DomainList = {Domains: Domains};
var Domains = util.makeArray(RefererConfiguration['DomainList'].Domain || []);
RefererConfiguration.DomainList = {Domains: Domains};
}

callback(null, {
Expand Down Expand Up @@ -7233,6 +7232,8 @@ function postObject(params, callback) {
headers['x-cos-grant-write'] = params['GrantWrite'];
headers['x-cos-grant-full-control'] = params['GrantFullControl'];
headers['x-cos-storage-class'] = params['StorageClass'];
headers['x-cos-mime-limit'] = params['MimeLimit'];
headers['x-cos-traffic-limit'] = params['TrafficLimit'];

// 删除 Content-Length 避免签名错误
delete headers['Content-Length'];
Expand Down Expand Up @@ -9684,6 +9685,14 @@ function uploadSliceItem(params, callback) {
ContentLength = end - start;
}

var headersWhiteList = ['x-cos-traffic-limit', 'x-cos-mime-limit'];
var headers = {};
util.each(Headers, function(v, k) {
if (headersWhiteList.indexOf(k) > -1) {
headers[k] = v;
}
});

util.fileSlice(FilePath, start, end, function (Body) {
var md5 = util.getFileMd5(Body);
var contentMd5 = md5 ? util.binaryBase64(md5) : null;
Expand All @@ -9700,6 +9709,7 @@ function uploadSliceItem(params, callback) {
UploadId: UploadData.UploadId,
ServerSideEncryption: ServerSideEncryption,
Body: Body,
Headers: headers,
onProgress: params.onProgress,
ContentMD5: contentMd5,
}, function (err, data) {
Expand Down
18 changes: 14 additions & 4 deletions demo/lib/cos-wx-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.0.11';
COS.version = '1.0.12';

module.exports = COS;

Expand Down Expand Up @@ -6432,9 +6432,8 @@ function getBucketReferer(params, callback) {

var RefererConfiguration = data.RefererConfiguration || {};
if (RefererConfiguration['DomainList']) {
var Domains = util.clone(RefererConfiguration['DomainList'].Domain || []);
Domains = util.makeArray(Domains);
RefererConfiguration.DomainList = {Domains: Domains};
var Domains = util.makeArray(RefererConfiguration['DomainList'].Domain || []);
RefererConfiguration.DomainList = {Domains: Domains};
}

callback(null, {
Expand Down Expand Up @@ -7233,6 +7232,8 @@ function postObject(params, callback) {
headers['x-cos-grant-write'] = params['GrantWrite'];
headers['x-cos-grant-full-control'] = params['GrantFullControl'];
headers['x-cos-storage-class'] = params['StorageClass'];
headers['x-cos-mime-limit'] = params['MimeLimit'];
headers['x-cos-traffic-limit'] = params['TrafficLimit'];

// 删除 Content-Length 避免签名错误
delete headers['Content-Length'];
Expand Down Expand Up @@ -9684,6 +9685,14 @@ function uploadSliceItem(params, callback) {
ContentLength = end - start;
}

var headersWhiteList = ['x-cos-traffic-limit', 'x-cos-mime-limit'];
var headers = {};
util.each(Headers, function(v, k) {
if (headersWhiteList.indexOf(k) > -1) {
headers[k] = v;
}
});

util.fileSlice(FilePath, start, end, function (Body) {
var md5 = util.getFileMd5(Body);
var contentMd5 = md5 ? util.binaryBase64(md5) : null;
Expand All @@ -9700,6 +9709,7 @@ function uploadSliceItem(params, callback) {
UploadId: UploadData.UploadId,
ServerSideEncryption: ServerSideEncryption,
Body: Body,
Headers: headers,
onProgress: params.onProgress,
ContentMD5: contentMd5,
}, function (err, data) {
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-wx-sdk-v5",
"version": "1.0.11",
"version": "1.0.12",
"description": "小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)",
"main": "demo/lib/cos-wx-sdk-v5.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ function uploadSliceItem(params, callback) {
ContentLength = end - start;
}

var headersWhiteList = ['x-cos-traffic-limit', 'x-cos-mime-limit'];
var headers = {};
util.each(Headers, function(v, k) {
if (headersWhiteList.indexOf(k) > -1) {
headers[k] = v;
}
});

util.fileSlice(FilePath, start, end, function (Body) {
var md5 = util.getFileMd5(Body);
var contentMd5 = md5 ? util.binaryBase64(md5) : null;
Expand All @@ -615,6 +623,7 @@ function uploadSliceItem(params, callback) {
UploadId: UploadData.UploadId,
ServerSideEncryption: ServerSideEncryption,
Body: Body,
Headers: headers,
onProgress: params.onProgress,
ContentMD5: contentMd5,
}, function (err, data) {
Expand Down
7 changes: 4 additions & 3 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,8 @@ function getBucketReferer(params, callback) {

var RefererConfiguration = data.RefererConfiguration || {};
if (RefererConfiguration['DomainList']) {
var Domains = util.clone(RefererConfiguration['DomainList'].Domain || []);
Domains = util.makeArray(Domains);
RefererConfiguration.DomainList = {Domains: Domains};
var Domains = util.makeArray(RefererConfiguration['DomainList'].Domain || []);
RefererConfiguration.DomainList = {Domains: Domains};
}

callback(null, {
Expand Down Expand Up @@ -1937,6 +1936,8 @@ function postObject(params, callback) {
headers['x-cos-grant-write'] = params['GrantWrite'];
headers['x-cos-grant-full-control'] = params['GrantFullControl'];
headers['x-cos-storage-class'] = params['StorageClass'];
headers['x-cos-mime-limit'] = params['MimeLimit'];
headers['x-cos-traffic-limit'] = params['TrafficLimit'];

// 删除 Content-Length 避免签名错误
delete headers['Content-Length'];
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '1.0.11';
COS.version = '1.0.12';

module.exports = COS;

0 comments on commit 91d23d7

Please sign in to comment.