Skip to content

Commit

Permalink
支持跨区域复制
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Oct 17, 2018
1 parent 7984950 commit e8a253a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 17 deletions.
10 changes: 7 additions & 3 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ var showLogText = function (text, color) {
var logger = {
log: function (text) {
console.log.apply(console, arguments);
showLogText([].join.call(arguments, ' '));
var args = [].map.call(arguments, function (v) {
return typeof v === 'object' ? JSON.stringify(v) : v;
});
showLogText(args.join(' '));
},
error: function (text) {
console.error(text);
Expand Down Expand Up @@ -439,9 +442,10 @@ function putBucketReplication() {
Rules: [{
ID: "1",
Status: "Enabled",
Prefix: "img/",
Prefix: "sync/",
Destination: {
Bucket: "qcs::cos:ap-guangzhou::test-" + AppId
Bucket: "qcs:id/0:cos:ap-chengdu:appid/" + AppId + ":backup",
StorageClass: "Standard",
},
}]
}
Expand Down
14 changes: 9 additions & 5 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
exports["COS"] = factory();
else
root["COS"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
Expand Down Expand Up @@ -111,7 +111,11 @@ var getAuth = function (opt) {
list.push(key);
}
}
return list.sort();
return list.sort(function (a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
return a === b ? 0 : a > b ? 1 : -1;
});
};

var obj2str = function (obj) {
Expand Down Expand Up @@ -1934,7 +1938,7 @@ util.extend(COS.prototype, base);
util.extend(COS.prototype, advance);

COS.getAuthorization = util.getAuth;
COS.version = '0.4.17';
COS.version = '0.4.18';

module.exports = COS;

Expand Down Expand Up @@ -4560,9 +4564,9 @@ function getBucketVersioning(params, callback) {

function putBucketReplication(params, callback) {
var ReplicationConfiguration = util.clone(params.ReplicationConfiguration);
ReplicationConfiguration.Rule = ReplicationConfiguration.Rules;
delete ReplicationConfiguration.Rules;
var xml = util.json2xml({ ReplicationConfiguration: ReplicationConfiguration });
xml = xml.replace(/<(\/?)Rules>/ig, '<$1Rule>');
xml = xml.replace(/<(\/?)Tags>/ig, '<$1Tag>');

var headers = params.Headers;
headers['Content-Type'] = 'application/xml';
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.4.17",
"version": "0.4.18",
"description": "cos js sdk v5",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion server/sts-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
);
}

function _hex2bin($data) {
$len = strlen($data);
return pack("H" . $len, $data);
}

// obj 转 query string
function json2str($obj, $notEncode = false) {
ksort($obj);
Expand All @@ -37,7 +42,7 @@ function getSignature($opt, $key, $method) {
global $config;
$formatString = $method . $config['Domain'] . '/v2/index.php?' . json2str($opt, 1);
$sign = hash_hmac('sha1', $formatString, $key);
$sign = base64_encode(hex2bin($sign));
$sign = base64_encode(_hex2bin($sign));
return $sign;
}

Expand Down
9 changes: 7 additions & 2 deletions server/sts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
'AllowPrefix' => '_ALLOW_DIR_/*', // 必填,这里改成允许的路径前缀,这里可以根据自己网站的用户登录态判断允许上传的目录,例子:* 或者 a/* 或者 a.jpg
);

function _hex2bin($data) {
$len = strlen($data);
return pack("H" . $len, $data);
}

// obj 转 query string
function json2str($obj, $notEncode = false) {
ksort($obj);
Expand All @@ -28,7 +33,7 @@ function getSignature($opt, $key, $method) {
global $config;
$formatString = $method . $config['Domain'] . '/v2/index.php?' . json2str($opt, 1);
$sign = hash_hmac('sha1', $formatString, $key);
$sign = base64_encode(hex2bin($sign));
$sign = base64_encode(_hex2bin($sign));
return $sign;
}

Expand All @@ -50,7 +55,7 @@ function getTempKeys() {
array(
'action'=> array(
// // 这里可以从临时密钥的权限上控制前端允许的操作
// 'name/cos:*', // 这样写可以包含下面所有权限
'name/cos:*', // 这样写可以包含下面所有权限

// // 列出所有允许的操作
// // ACL 读写
Expand Down
4 changes: 2 additions & 2 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,9 @@ function getBucketVersioning(params, callback) {

function putBucketReplication(params, callback) {
var ReplicationConfiguration = util.clone(params.ReplicationConfiguration);
ReplicationConfiguration.Rule = ReplicationConfiguration.Rules;
delete ReplicationConfiguration.Rules;
var xml = util.json2xml({ReplicationConfiguration: ReplicationConfiguration});
xml = xml.replace(/<(\/?)Rules>/ig, '<$1Rule>');
xml = xml.replace(/<(\/?)Tags>/ig, '<$1Tag>');

var headers = params.Headers;
headers['Content-Type'] = 'application/xml';
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ util.extend(COS.prototype, base);
util.extend(COS.prototype, advance);

COS.getAuthorization = util.getAuth;
COS.version = '0.4.17';
COS.version = '0.4.18';

module.exports = COS;
6 changes: 5 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ var getAuth = function (opt) {
list.push(key);
}
}
return list.sort();
return list.sort(function (a, b) {
a = a.toLowerCase();
b = b.toLowerCase();
return a === b ? 0 : (a > b ? 1 : -1);
});
};

var obj2str = function (obj) {
Expand Down

0 comments on commit e8a253a

Please sign in to comment.