Skip to content

Commit

Permalink
修改 Location 错误
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jan 11, 2018
1 parent 5010b4b commit 13c3044
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function getObjectUrl() {
Region: config.Region,
Key: '1mb.zip',
Expires: 60,
Sign: true,
}, function (err, data) {
console.log(err || data);
});
Expand Down Expand Up @@ -380,7 +381,7 @@ function deleteBucketReplication() {
function deleteBucket() {
cos.deleteBucket({
Bucket: 'testnew',
Region: config.Region
Region: 'ap-guangzhou'
}, function (err, data) {
console.log(err || data);
});
Expand Down
4 changes: 2 additions & 2 deletions 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.3.3",
"version": "0.3.4",
"description": "cos js sdk v5",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 0 additions & 3 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ function getUploadIdAndPartList(params, callback) {
var SliceCount = Math.ceil(FileSize / SliceSize);
var FinishSliceCount = 0;
var FinishSize = 0;
var progressTimer = 0;
var time0 = 0;
var size0 = 0;
var onHashProgress = util.throttleOnProgress.call(self, FileSize, params.onHashProgress);
var getChunkETag = function (PartNumber, callback) {
var start = SliceSize * (PartNumber - 1);
Expand Down
25 changes: 25 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,15 @@ function putObject(params, callback) {
return callback(err);
}
if (data && data.headers && data.headers['etag']) {
var url = getUrl({
domain: self.options.Domain,
bucket: params.Bucket,
region: params.Region,
appId: params.AppId,
object: params.Key,
});
return callback(null, {
Location: url,
ETag: data.headers['etag'],
statusCode: data.statusCode,
headers: data.headers,
Expand Down Expand Up @@ -1469,6 +1477,7 @@ function multipartUpload(params, callback) {
* @return {Object} data.CompleteMultipartUpload 完成分块上传后的文件信息,包括Location, Bucket, Key 和 ETag
*/
function multipartComplete(params, callback) {
var self = this;
var headers = {};

headers['Content-Type'] = 'application/xml';
Expand Down Expand Up @@ -1510,7 +1519,16 @@ function multipartComplete(params, callback) {
if (err) {
return callback(err);
}
var url = getUrl({
domain: self.options.Domain,
bucket: params.Bucket,
region: params.Region,
appId: params.AppId,
object: params.Key,
isLocation: true,
});
var result = util.extend(data.CompleteMultipartUploadResult, {
Location: url,
statusCode: data.statusCode,
headers: data.headers,
});
Expand Down Expand Up @@ -1699,6 +1717,10 @@ function getObjectUrl(params, callback) {
appId: params.AppId || self.options.AppId || '',
object: params.Key,
});
if (params.Sign !== undefined && !params.Sign) {
callback(null, {Url: url});
return url;
}
var authorization = getAuthorizationAsync.call(this, {
Method: params.Method || 'get',
Key: params.Key,
Expand Down Expand Up @@ -1802,6 +1824,9 @@ function getUrl(params) {
if (action) {
url += action;
}
if (params.isLocation) {
url = url.replace(/^https?:\/\//, '');
}
return url;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ util.extend(COS.prototype, base);
util.extend(COS.prototype, advance);

COS.getAuthorization = util.getAuth;
COS.version = '0.3.3';
COS.version = '0.3.4';

module.exports = COS;

0 comments on commit 13c3044

Please sign in to comment.