Skip to content

Commit

Permalink
补充 ACL、CORS 接口兼容老格式
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Apr 25, 2019
1 parent 94ae5c6 commit e0b4045
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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.5.8",
"version": "2.5.9",
"description": "cos nodejs sdk v5",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions sdk/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2660,9 +2660,25 @@ var API_MAP = {
getV4Auth: getV4Auth,
};

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);
});
};

0 comments on commit e0b4045

Please sign in to comment.