Skip to content

Commit

Permalink
Update demo.js
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu authored Apr 8, 2018
1 parent 47b39db commit 7c32b9e
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ var util = {

var getAuthorization = function (options, callback) {

// 方法一、后端计算签名(推荐
// 方法一、后端通过获取临时密钥,计算签名给到前端(适用于前端调试
var method = (options.Method || 'get').toLowerCase();
var key = options.Key || '';
var query = options.Query || {};
var headers = options.Headers || {};
var pathname = key.indexOf('/') === 0 ? key : '/' + key;
// var url = 'http://127.0.0.1:3000/auth';
var url = '../server/auth.php';
// var url = 'http://127.0.0.1:3000/sts';
var url = '../server/sts.php';
var xhr = new XMLHttpRequest();
var data = {
method: method,
Expand All @@ -37,18 +37,25 @@ var getAuthorization = function (options, callback) {
xhr.open('POST', url, true);
xhr.setRequestHeader('content-type', 'application/json');
xhr.onload = function (e) {
callback(e.target.responseText);
try {
var AuthData = JSON.parse(e.target.responseText);
} catch (e) {
}
callback({
Authorization: AuthData.authorization,
XCosSecurityToken: AuthData.sessionToken,
});
};
xhr.send(JSON.stringify(data));

// // 方法二、后端通过获取临时密钥,计算签名给到前端(适用于前端调试
// // 方法二、后端计算签名(推荐
// var method = (options.Method || 'get').toLowerCase();
// var key = options.Key || '';
// var query = options.Query || {};
// var headers = options.Headers || {};
// var pathname = key.indexOf('/') === 0 ? key : '/' + key;
// // var url = 'http://127.0.0.1:3000/sts';
// var url = '../server/sts.php';
// // var url = 'http://127.0.0.1:3000/auth';
// var url = '../server/auth.php';
// var xhr = new XMLHttpRequest();
// var data = {
// method: method,
Expand All @@ -59,14 +66,7 @@ var getAuthorization = function (options, callback) {
// xhr.open('POST', url, true);
// xhr.setRequestHeader('content-type', 'application/json');
// xhr.onload = function (e) {
// try {
// var AuthData = JSON.parse(e.target.responseText);
// } catch (e) {
// }
// callback({
// Authorization: AuthData.authorization,
// XCosSecurityToken: AuthData.sessionToken,
// });
// callback(e.target.responseText);
// };
// xhr.send(JSON.stringify(data));

Expand All @@ -81,17 +81,8 @@ var getAuthorization = function (options, callback) {

};

var getSTS = function (params, callback) {
callback({
SecretId: 'xxx',
SecretKey: 'xxx',
XCosSecurityToken: 'xxx',
});
};

var cos = new COS({
getAuthorization: getAuthorization,
// getSTS: getSTS,
});
var TaskId;

Expand Down

0 comments on commit 7c32b9e

Please sign in to comment.