Skip to content

Commit

Permalink
修复 AdGuard 插件导致 Blob 判断出错
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jul 13, 2018
1 parent 9124907 commit acccbef
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ console.error = function (text) {
};

function getAuth() {
var key = '1mb.zip';
var key = '1.png';
getAuthorization({
Method: 'get',
Key: key
Expand Down
16 changes: 7 additions & 9 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -5441,15 +5441,13 @@ function getObjectUrl(params, callback) {
Expires: params.Expires
}, function (AuthData) {
if (!callback) return;
var result = {
Url: url + '?sign=' + encodeURIComponent(AuthData.Authorization)
};
AuthData.XCosSecurityToken && (result.XCosSecurityToken = AuthData.XCosSecurityToken);
AuthData.ClientIP && (result.ClientIP = AuthData.ClientIP);
AuthData.ClientUA && (result.ClientUA = AuthData.ClientUA);
AuthData.Token && (result.Token = AuthData.Token);
url += '?sign=' + encodeURIComponent(AuthData.Authorization);
AuthData.XCosSecurityToken && (url += '&x-cos-security-token=' + AuthData.XCosSecurityToken);
AuthData.ClientIP && (url += '&clientIP=' + AuthData.ClientIP);
AuthData.ClientUA && (url += '&clientua=' + AuthData.ClientUA);
AuthData.Token && (url += '&token=' + AuthData.Token);
setTimeout(function () {
callback(null, result);
callback(null, { Url: url });
});
});
if (authorization) {
Expand Down Expand Up @@ -9970,7 +9968,7 @@ var request = function (options, callback) {

// body
if (options.body) {
if (options.body.constructor !== window.File && options.body.constructor !== window.Blob) {
if (!(options.body instanceof window.Blob)) {
options.data = options.body;
delete options.body;
}
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 lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4134,7 +4134,7 @@ var request = function (options, callback) {

// body
if (options.body) {
if (options.body.constructor !== window.File && options.body.constructor !== window.Blob) {
if (!(options.body instanceof window.Blob)) {
options.data = options.body;
delete options.body;
}
Expand Down
14 changes: 6 additions & 8 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1648,15 +1648,13 @@ function getObjectUrl(params, callback) {
Expires: params.Expires,
}, function (AuthData) {
if (!callback) return;
var result = {
Url: url + '?sign=' + encodeURIComponent(AuthData.Authorization),
};
AuthData.XCosSecurityToken && (result.XCosSecurityToken = AuthData.XCosSecurityToken);
AuthData.ClientIP && (result.ClientIP = AuthData.ClientIP);
AuthData.ClientUA && (result.ClientUA = AuthData.ClientUA);
AuthData.Token && (result.Token = AuthData.Token);
url += '?sign=' + encodeURIComponent(AuthData.Authorization);
AuthData.XCosSecurityToken && (url += '&x-cos-security-token=' + AuthData.XCosSecurityToken);
AuthData.ClientIP && (url += '&clientIP=' + AuthData.ClientIP);
AuthData.ClientUA && (url += '&clientua=' + AuthData.ClientUA);
AuthData.Token && (url += '&token=' + AuthData.Token);
setTimeout(function () {
callback(null, result);
callback(null, {Url: url});
});
});
if (authorization) {
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var config = {
Bucket: 'test-1256263624',
Bucket: 'test-1251902136',
Region: 'ap-guangzhou'
};

Expand Down Expand Up @@ -30,9 +30,9 @@ var util = {
var getAuthorization = function (options, callback) {

// 方法一、后端通过获取临时密钥,计算签名给到前端(适用于前端调试)
var url = 'http://127.0.0.1:3000/sts?Bucket=' + options.Bucket + '&Region=' + options.Region;
// var url = 'http://127.0.0.1:3000/sts?Bucket=' + options.Bucket + '&Region=' + options.Region;
// var url = '../server/sts.php?Bucket=' + options.Bucket + '&Region=' + options.Region;
// var url = '../server/sts.php';
var url = '../server/sts.php';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (e) {
Expand Down Expand Up @@ -1511,7 +1511,7 @@ it('params check', function (assert) {
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: 'gz'
}, function (err, data) {
assert.ok(err.error.indexOf('param Region format error') === 0);
assert.ok(err.error === 'error');
done();
});
});
Expand Down

0 comments on commit acccbef

Please sign in to comment.