Skip to content

Commit 7c32b9e

Browse files
authored
Update demo.js
1 parent 47b39db commit 7c32b9e

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

demo/demo.js

+15-24
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ var util = {
1919

2020
var getAuthorization = function (options, callback) {
2121

22-
// 方法一、后端计算签名(推荐
22+
// 方法一、后端通过获取临时密钥,计算签名给到前端(适用于前端调试
2323
var method = (options.Method || 'get').toLowerCase();
2424
var key = options.Key || '';
2525
var query = options.Query || {};
2626
var headers = options.Headers || {};
2727
var pathname = key.indexOf('/') === 0 ? key : '/' + key;
28-
// var url = 'http://127.0.0.1:3000/auth';
29-
var url = '../server/auth.php';
28+
// var url = 'http://127.0.0.1:3000/sts';
29+
var url = '../server/sts.php';
3030
var xhr = new XMLHttpRequest();
3131
var data = {
3232
method: method,
@@ -37,18 +37,25 @@ var getAuthorization = function (options, callback) {
3737
xhr.open('POST', url, true);
3838
xhr.setRequestHeader('content-type', 'application/json');
3939
xhr.onload = function (e) {
40-
callback(e.target.responseText);
40+
try {
41+
var AuthData = JSON.parse(e.target.responseText);
42+
} catch (e) {
43+
}
44+
callback({
45+
Authorization: AuthData.authorization,
46+
XCosSecurityToken: AuthData.sessionToken,
47+
});
4148
};
4249
xhr.send(JSON.stringify(data));
4350

44-
// // 方法二、后端通过获取临时密钥,计算签名给到前端(适用于前端调试
51+
// // 方法二、后端计算签名(推荐
4552
// var method = (options.Method || 'get').toLowerCase();
4653
// var key = options.Key || '';
4754
// var query = options.Query || {};
4855
// var headers = options.Headers || {};
4956
// var pathname = key.indexOf('/') === 0 ? key : '/' + key;
50-
// // var url = 'http://127.0.0.1:3000/sts';
51-
// var url = '../server/sts.php';
57+
// // var url = 'http://127.0.0.1:3000/auth';
58+
// var url = '../server/auth.php';
5259
// var xhr = new XMLHttpRequest();
5360
// var data = {
5461
// method: method,
@@ -59,14 +66,7 @@ var getAuthorization = function (options, callback) {
5966
// xhr.open('POST', url, true);
6067
// xhr.setRequestHeader('content-type', 'application/json');
6168
// xhr.onload = function (e) {
62-
// try {
63-
// var AuthData = JSON.parse(e.target.responseText);
64-
// } catch (e) {
65-
// }
66-
// callback({
67-
// Authorization: AuthData.authorization,
68-
// XCosSecurityToken: AuthData.sessionToken,
69-
// });
69+
// callback(e.target.responseText);
7070
// };
7171
// xhr.send(JSON.stringify(data));
7272

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

8282
};
8383

84-
var getSTS = function (params, callback) {
85-
callback({
86-
SecretId: 'xxx',
87-
SecretKey: 'xxx',
88-
XCosSecurityToken: 'xxx',
89-
});
90-
};
91-
9284
var cos = new COS({
9385
getAuthorization: getAuthorization,
94-
// getSTS: getSTS,
9586
});
9687
var TaskId;
9788

0 commit comments

Comments
 (0)