Skip to content

Commit 2d1313e

Browse files
authored
Feat/2.12.0 (#169)
* feat: 新增cov命令 * fix: 补充d.ts * feat: 补充ci智能语音和云查毒接口 * fix: 修复Body类型 * fix: 更新依赖库版本 * upd: version * fix: 恢复版本 * upd: 新增单测 * upd: 新增单测 * upd: 新增单测 * upd: 新增单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * feat: uploadSliceItem透传headers * upd: 补充单测 * upd: 补充单测 * upd: 更好xml2js * feat: 默认关闭FollowRedirect
1 parent 37c87e0 commit 2d1313e

File tree

6 files changed

+1247
-161
lines changed

6 files changed

+1247
-161
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.11.19",
3+
"version": "2.12.0",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "index.d.ts",
@@ -32,9 +32,9 @@
3232
"homepage": "https://github.com/tencentyun/cos-nodejs-sdk-v5#readme",
3333
"dependencies": {
3434
"conf": "^9.0.0",
35+
"fast-xml-parser": "^4.2.2",
3536
"mime-types": "^2.1.24",
36-
"request": "^2.88.2",
37-
"xml2js": "^0.4.19"
37+
"request": "^2.88.2"
3838
},
3939
"devDependencies": {
4040
"@types/node": "^14.14.20",

sdk/advance.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function sliceUploadFile(params, callback) {
8888
AsyncLimit: AsyncLimit,
8989
ServerSideEncryption: ServerSideEncryption,
9090
UploadData: UploadData,
91+
Headers: params.Headers,
9192
onProgress: onProgress
9293
}, function (err, data) {
9394
if (!self._isRunningTask(TaskId)) return;
@@ -537,6 +538,7 @@ function uploadSliceList(params, cb) {
537538
ServerSideEncryption: ServerSideEncryption,
538539
FilePath: FilePath,
539540
UploadData: UploadData,
541+
Headers: params.Headers,
540542
onProgress: function (data) {
541543
FinishSize += data.loaded - preAddSize;
542544
preAddSize = data.loaded;
@@ -1306,7 +1308,8 @@ function downloadFile(params, callback) {
13061308
['DEEP_ARCHIVE', 'ARCHIVE'].includes(storageClass) &&
13071309
(!restoreStatus || restoreStatus === 'ongoing-request="true"')
13081310
) {
1309-
return callback({statusCode, header: resHeaders, code: 'CannotDownload', message: 'Archive object can not download, please restore to Standard storage class.'});
1311+
// 自定义返回的错误码 与cos api无关
1312+
return callback({statusCode: 403, header: resHeaders, code: 'CannotDownload', message: 'Archive object can not download, please restore to Standard storage class.'});
13101313
}
13111314

13121315
// 整理文件信息

sdk/base.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ function putBucket(params, callback) {
8888
if (params.BucketAZConfig) conf.BucketAZConfig = params.BucketAZConfig;
8989
if (params.BucketArchConfig) conf.BucketArchConfig = params.BucketArchConfig;
9090
if (conf.BucketAZConfig || conf.BucketArchConfig) xml = util.json2xml({CreateBucketConfiguration: conf});
91-
console.log(xml);
9291

9392
submitRequest.call(this, {
9493
Action: 'name/cos:PutBucket',

sdk/cos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var defaultOptions = {
3939
Ip: '',
4040
StrictSsl: true,
4141
KeepAlive: true,
42-
FollowRedirect: true,
42+
FollowRedirect: false,
4343
UseAccelerate: false,
4444
UserAgent: '',
4545
ConfCwd: '',

sdk/util.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
var fs = require('fs');
44
var crypto = require('crypto');
5-
var xml2js = require('xml2js');
6-
var xmlParser = new xml2js.Parser({explicitArray: false, ignoreAttrs: true});
7-
var xmlBuilder = new xml2js.Builder();
5+
var { XMLParser, XMLBuilder } = require('fast-xml-parser');
6+
var xmlParser = new XMLParser({ ignoreAttributes: true });
7+
var xmlBuilder = new XMLBuilder();
88

99
function camSafeUrlEncode(str) {
1010
return encodeURIComponent(str)
@@ -187,17 +187,14 @@ var clearKey = function (obj) {
187187

188188
// XML 对象转 JSON 对象
189189
var xml2json = function (bodyStr) {
190-
var d = {};
191-
xmlParser.parseString(bodyStr, function (err, result) {
192-
d = result;
193-
});
190+
var d = xmlParser.parse(bodyStr);
194191

195192
return d;
196193
};
197194

198195
// JSON 对象转 XML 对象
199196
var json2xml = function (json) {
200-
var xml = xmlBuilder.buildObject(json);
197+
var xml = xmlBuilder.build(json);
201198
return xml;
202199
};
203200

0 commit comments

Comments
 (0)