Skip to content

Commit

Permalink
fix authorization error
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed May 15, 2019
1 parent fe74e2d commit 7e8a406
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
22 changes: 21 additions & 1 deletion dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.15';
COS.version = '0.5.16';

module.exports = COS;

Expand Down Expand Up @@ -6089,6 +6089,10 @@ function submitRequest(params, callback) {
ResourceKey: params.ResourceKey,
Scope: params.Scope
}, function (err, AuthData) {
if (err) {
callback(err);
return;
}
params.AuthData = AuthData;
_submitRequest.call(self, params, function (err, data) {
if (err && tryIndex < 2 && (oldClockOffset !== self.options.SystemClockOffset || allowRetry.call(self, err))) {
Expand Down Expand Up @@ -6291,10 +6295,26 @@ var API_MAP = {
getAuth: getAuth
};

function warnOldApi(apiName, fn, proto) {
util.each(['Cors', 'Acl'], function (suffix) {
if (apiName.slice(-suffix.length) === suffix) {
var oldName = apiName.slice(0, -suffix.length) + suffix.toUpperCase();
var apiFn = util.apiWrapper(apiName, fn);
var warned = false;
proto[oldName] = function () {
!warned && console.warn('warning: cos.' + oldName + ' has been deprecated. Please Use cos.' + apiName + ' instead.');
warned = true;
apiFn.apply(this, arguments);
};
}
});
}

module.exports.init = function (COS, task) {
task.transferToTaskMethod(API_MAP, 'putObject');
util.each(API_MAP, function (fn, apiName) {
COS.prototype[apiName] = util.apiWrapper(apiName, fn);
warnOldApi(apiName, fn, COS.prototype);
});
};

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.15",
"version": "0.5.16",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,10 @@ function submitRequest(params, callback) {
ResourceKey: params.ResourceKey,
Scope: params.Scope,
}, function (err, AuthData) {
if (err) {
callback(err);
return;
}
params.AuthData = AuthData;
_submitRequest.call(self, params, function (err, data) {
if (err && tryIndex < 2 && (oldClockOffset !== self.options.SystemClockOffset || allowRetry.call(self, err))) {
Expand Down Expand Up @@ -2409,9 +2413,25 @@ var API_MAP = {
getAuth: getAuth,
};

function warnOldApi(apiName, fn, proto) {
util.each(['Cors', 'Acl'], function (suffix) {
if (apiName.slice(-suffix.length) === suffix) {
var oldName = apiName.slice(0, -suffix.length) + suffix.toUpperCase();
var apiFn = util.apiWrapper(apiName, fn);
var warned = false;
proto[oldName] = function () {
!warned && console.warn('warning: cos.' + oldName + ' has been deprecated. Please Use cos.' + apiName + ' instead.');
warned = true;
apiFn.apply(this, arguments);
};
}
});
}

module.exports.init = function (COS, task) {
task.transferToTaskMethod(API_MAP, 'putObject');
util.each(API_MAP, function (fn, apiName) {
COS.prototype[apiName] = util.apiWrapper(apiName, fn);
warnOldApi(apiName, fn, COS.prototype);
});
};
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.15';
COS.version = '0.5.16';

module.exports = COS;

0 comments on commit 7e8a406

Please sign in to comment.