Skip to content

Commit

Permalink
support csp
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Sep 10, 2018
1 parent ce0df94 commit d48456c
Show file tree
Hide file tree
Showing 13 changed files with 2,531 additions and 49 deletions.
860 changes: 860 additions & 0 deletions demo/csp.html

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ var apiWrapper = function (apiName, apiFn) {
return;
}
// 判断 region 格式
if (!this.options.IgnoreRegionFormat && params.Region && params.Region.indexOf('-') === -1 && params.Region !== 'yfb' && params.Region !== 'default') {
if (!this.options.CompatibilityMode && params.Region && params.Region.indexOf('-') === -1 && params.Region !== 'yfb' && params.Region !== 'default') {
console.warn('param Region format error, find help here: https://cloud.tencent.com/document/product/436/6224');
}
// 判断 region 格式
Expand Down Expand Up @@ -508,7 +508,7 @@ var getFileSize = function (api, params, callback) {
} else {
if (params.Body !== undefined) {
if (typeof params.Body === 'string') {
params.Body = global.Buffer(params.Body);
params.Body = global.Buffer.from(params.Body);
}
if (params.Body instanceof global.Buffer) {
size = params.Body.length;
Expand Down Expand Up @@ -1896,14 +1896,16 @@ var defaultOptions = {
ChunkRetryTimes: 3,
ChunkSize: 1024 * 1024,
SliceSize: 1024 * 1024,
CopyChunkParallelLimit: 20,
CopyChunkSize: 1024 * 1024 * 10,
CopySliceSize: 1024 * 1024 * 10,
ProgressInterval: 1000,
UploadQueueSize: 10000,
Domain: '',
ServiceDomain: '',
Protocol: '',
IgnoreRegionFormat: false,
UploadIdCacheLimit: 50,
CopySliceSize: 1024 * 1024 * 1024 * 50
CompatibilityMode: false,
UploadIdCacheLimit: 50
};

// 对外暴露的类
Expand All @@ -1913,6 +1915,8 @@ var COS = function (options) {
this.options.ChunkParallelLimit = Math.max(1, this.options.ChunkParallelLimit);
this.options.ChunkRetryTimes = Math.max(0, this.options.ChunkRetryTimes);
this.options.ChunkSize = Math.max(1024 * 1024, this.options.ChunkSize);
this.options.CopyChunkParallelLimit = Math.max(1, this.options.CopyChunkParallelLimit);
this.options.CopyChunkSize = Math.max(1024 * 1024, this.options.CopyChunkSize);
this.options.CopySliceSize = Math.max(0, this.options.CopySliceSize);
if (this.options.AppId) {
console.warn('warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").');
Expand Down Expand Up @@ -2528,7 +2532,8 @@ var xmlToJSON = function () {
}

if (!Object.keys(vResult).length) {
vResult = sCollectedTxt.replace(trimMatch, '') || '';
// vResult = sCollectedTxt.replace(trimMatch, '') || ''; // by carsonxu 修复 getBucket返回的 Key 是 " /" 这种场景
vResult = sCollectedTxt || '';
}

return vResult;
Expand Down Expand Up @@ -3589,14 +3594,14 @@ function esc(str) {
}

module.exports = function (obj, options) {

if (!options) {
options = {
xmlHeader: {
standalone: true
},
prettyPrint: true,
indent: " "
indent: " ",
escape: true
};
}

Expand Down Expand Up @@ -3745,7 +3750,6 @@ var initTask = function (cos) {

// 复制参数对象
params = util.extend({}, params);
ignoreAddEvent && (params.ignoreAddEvent = true);

// 生成 id
var id = util.uuid();
Expand Down Expand Up @@ -3802,7 +3806,7 @@ var initTask = function (cos) {
return;
}
task.size = size;
!params.IgnoreAddEvent && emitListUpdate();
!ignoreAddEvent && emitListUpdate();
startNextTask(cos);
});
return id;
Expand Down Expand Up @@ -4638,14 +4642,20 @@ function headObject(params, callback) {
}

function listObjectVersions(params, callback) {
var reqParams = {};
reqParams['prefix'] = params['Prefix'];
reqParams['delimiter'] = params['Delimiter'];
reqParams['key-marker'] = params['KeyMarker'];
reqParams['version-id-marker'] = params['VersionIdMarker'];
reqParams['max-keys'] = params['MaxKeys'];
reqParams['encoding-type'] = params['EncodingType'];

submitRequest.call(this, {
method: 'GET',
Bucket: params.Bucket,
Region: params.Region,
headers: params.Headers,
qs: {
prefix: params.Prefix
},
qs: reqParams,
action: 'versions'
}, function (err, data) {
if (err) {
Expand Down Expand Up @@ -11211,7 +11221,7 @@ function sliceCopyFile(params, callback) {
var Region = params.Region;
var Key = params.Key;
var CopySource = params.CopySource;
var m = CopySource.match(/^([^.]+-\d+)\.cos\.([^.]+)\.myqcloud\.com\/(.+)$/);
var m = CopySource.match(/^([^.]+-\d+)\.cos\.([^.]+)\.[^/]+\/(.+)$/);
if (!m) {
callback({ error: 'CopySource format error' });
return;
Expand All @@ -11224,8 +11234,7 @@ function sliceCopyFile(params, callback) {
CopySliceSize = Math.max(0, Math.min(CopySliceSize, 5 * 1024 * 1024 * 1024));

var ChunkSize = params.ChunkSize || this.options.ChunkSize;

var ChunkParallel = this.options.ChunkParallelLimit;
var ChunkParallel = this.options.CopyChunkParallelLimit;

var FinishSize = 0;
var FileSize;
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/json2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ function esc(str) {
}

module.exports = function (obj, options) {

if (!options) {
options = {
xmlHeader: {
standalone: true
},
prettyPrint: true,
indent: " "
indent: " ",
escape: true,
};
}

Expand Down
3 changes: 2 additions & 1 deletion lib/xml2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ var xmlToJSON = (function () {
}

if (!Object.keys(vResult).length) {
vResult = sCollectedTxt.replace(trimMatch, '') || '';
// vResult = sCollectedTxt.replace(trimMatch, '') || ''; // by carsonxu 修复 getBucket返回的 Key 是 " /" 这种场景
vResult = sCollectedTxt || '';
}

return vResult;
Expand Down
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.14",
"version": "0.4.15",
"description": "cos js sdk v5",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ function sliceCopyFile(params, callback) {
var Region = params.Region;
var Key = params.Key;
var CopySource = params.CopySource;
var m = CopySource.match(/^([^.]+-\d+)\.cos\.([^.]+)\.myqcloud\.com\/(.+)$/);
var m = CopySource.match(/^([^.]+-\d+)\.cos\.([^.]+)\.[^/]+\/(.+)$/);
if (!m) {
callback({error: 'CopySource format error'});
return;
Expand All @@ -963,8 +963,7 @@ function sliceCopyFile(params, callback) {
CopySliceSize = Math.max(0, Math.min(CopySliceSize, 5 * 1024 * 1024 * 1024));

var ChunkSize = params.ChunkSize || this.options.ChunkSize;

var ChunkParallel = this.options.ChunkParallelLimit;
var ChunkParallel = this.options.CopyChunkParallelLimit;

var FinishSize = 0;
var FileSize;
Expand Down
12 changes: 9 additions & 3 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,14 +805,20 @@ function headObject(params, callback) {


function listObjectVersions(params, callback) {
var reqParams = {};
reqParams['prefix'] = params['Prefix'];
reqParams['delimiter'] = params['Delimiter'];
reqParams['key-marker'] = params['KeyMarker'];
reqParams['version-id-marker'] = params['VersionIdMarker'];
reqParams['max-keys'] = params['MaxKeys'];
reqParams['encoding-type'] = params['EncodingType'];

submitRequest.call(this, {
method: 'GET',
Bucket: params.Bucket,
Region: params.Region,
headers: params.Headers,
qs: {
prefix: params.Prefix
},
qs: reqParams,
action: 'versions',
}, function (err, data) {
if (err) {
Expand Down
8 changes: 6 additions & 2 deletions src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ var defaultOptions = {
ChunkRetryTimes: 3,
ChunkSize: 1024 * 1024,
SliceSize: 1024 * 1024,
CopyChunkParallelLimit: 20,
CopyChunkSize: 1024 * 1024 * 10,
CopySliceSize: 1024 * 1024 * 10,
ProgressInterval: 1000,
UploadQueueSize: 10000,
Domain: '',
ServiceDomain: '',
Protocol: '',
IgnoreRegionFormat: false,
CompatibilityMode: false,
UploadIdCacheLimit: 50,
CopySliceSize: 1024 * 1024 * 1024 * 50,
};

// 对外暴露的类
Expand All @@ -32,6 +34,8 @@ var COS = function (options) {
this.options.ChunkParallelLimit = Math.max(1, this.options.ChunkParallelLimit);
this.options.ChunkRetryTimes = Math.max(0, this.options.ChunkRetryTimes);
this.options.ChunkSize = Math.max(1024 * 1024, this.options.ChunkSize);
this.options.CopyChunkParallelLimit = Math.max(1, this.options.CopyChunkParallelLimit);
this.options.CopyChunkSize = Math.max(1024 * 1024, this.options.CopyChunkSize);
this.options.CopySliceSize = Math.max(0, this.options.CopySliceSize);
if (this.options.AppId) {
console.warn('warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").');
Expand Down
3 changes: 1 addition & 2 deletions src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var initTask = function (cos) {

// 复制参数对象
params = util.extend({}, params);
ignoreAddEvent && (params.ignoreAddEvent = true);

// 生成 id
var id = util.uuid();
Expand Down Expand Up @@ -169,7 +168,7 @@ var initTask = function (cos) {
return;
}
task.size = size;
!params.IgnoreAddEvent && emitListUpdate();
!ignoreAddEvent && emitListUpdate();
startNextTask(cos);
});
return id;
Expand Down
4 changes: 2 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ var apiWrapper = function (apiName, apiFn) {
return;
}
// 判断 region 格式
if (!this.options.IgnoreRegionFormat && params.Region && params.Region.indexOf('-') === -1 && params.Region !== 'yfb' && params.Region !== 'default') {
if (!this.options.CompatibilityMode && params.Region && params.Region.indexOf('-') === -1 && params.Region !== 'yfb' && params.Region !== 'default') {
console.warn('param Region format error, find help here: https://cloud.tencent.com/document/product/436/6224');
}
// 判断 region 格式
Expand Down Expand Up @@ -441,7 +441,7 @@ var getFileSize = function (api, params, callback) {
} else {
if (params.Body !== undefined) {
if (typeof params.Body === 'string') {
params.Body = global.Buffer(params.Body);
params.Body = global.Buffer.from(params.Body);
}
if (params.Body instanceof global.Buffer) {
size = params.Body.length;
Expand Down
Loading

0 comments on commit d48456c

Please sign in to comment.