Skip to content

Fix/2.12.1 (#1) #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2326,8 +2326,8 @@ declare class COS {
appendObject(params: COS.AppendObjectParams): Promise<COS.GeneralResult>;

/** 分块下载 @see https://cloud.tencent.com/document/product/436/64981#.E5.88.86.E5.9D.97.E4.B8.8B.E8.BD.BD.E5.AF.B9.E8.B1.A1 */
downloadFile(params: COS.DownloadFileParams, callback: (err: COS.CosError, data: COS.GeneralResult) => void): void;
downloadFile(params: COS.DownloadFileParams): Promise<COS.GeneralResult>;
downloadFile(params: COS.DownloadFileParams, callback: (err: COS.CosError, data: COS.GetObjectResult) => void): void;
downloadFile(params: COS.DownloadFileParams): Promise<COS.GetObjectResult>;

/** 获取 COS JSON API (v4) 签名 @see https://cloud.tencent.com/document/product/436/6054 */
getV4Auth(params: COS.GetV4AuthParams): COS.Authorization;
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-nodejs-sdk-v5",
"version": "2.12.0",
"version": "2.12.1",
"description": "cos nodejs sdk v5",
"main": "index.js",
"types": "index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion sdk/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
var fs = require('fs');
var crypto = require('crypto');
var { XMLParser, XMLBuilder } = require('fast-xml-parser');
var xmlParser = new XMLParser({ ignoreAttributes: true });
var xmlParser = new XMLParser({
ignoreDeclaration: true, // 忽略 XML 声明
ignoreAttributes: true, // 忽略属性
parseTagValue: false, // 关闭自动解析
});
var xmlBuilder = new XMLBuilder();

function camSafeUrlEncode(str) {
Expand Down
136 changes: 136 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,96 @@ group('init cos', function() {
});
putFile(initCos, done, assert);
});
test('SecretKey格式错误', function(done, assert) {
var initCos = new COS({
SecretId: config.SecretId,
SecretKey: config.SecretKey + ' ',
});
putFile(initCos, done, assert, false);
});
test('StrictSsl=false', function(done, assert) {
var initCos = new COS({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
StrictSsl: false,
});
putFile(initCos, done, assert, true);
});
test('Tunnel=false', function(done, assert) {
var initCos = new COS({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Tunnel: false,
});
putFile(initCos, done, assert, true);
});
test('Timeout=6000', function(done, assert) {
var initCos = new COS({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Timeout: 6000,
});
putFile(initCos, done, assert, true);
});
test('模拟sms init', function(done, assert) {
var Credentials = {
secretId: config.SecretId,
secretKey: config.SecretKey,
};
var initCos = new COS({ Credentials });
setTimeout(() => {
Credentials.secretId = '123456';
Credentials.secretKey = 'abcdefg';
}, 1000);
putFile(initCos, done, assert, true);
});
test('getAuthorization error tmpSecretId', function(done, assert) {
var initCos = new COS({
getAuthorization: function (options, callback) {
callback({
tmpSecretId: config.SecretId,
TmpSecretKey: config.SecretKey,
});
}
});
putFile(initCos, done, assert, false);
});
test('getAuthorization error tmpSecretKey', function(done, assert) {
var initCos = new COS({
getAuthorization: function (options, callback) {
callback({
TmpSecretId: config.SecretId,
tmpSecretKey: config.SecretKey,
});
}
});
putFile(initCos, done, assert, false);
});
test('getAuthorization error', function(done, assert) {
var initCos = new COS({
getAuthorization: function (options, callback) {
callback({
TmpSecretId: config.SecretId,
TmpSecretKey: config.SecretKey,
});
}
});
putFile(initCos, done, assert, false);
});
test('getAuthorization', function(done, assert) {
var initCos = new COS({
getAuthorization: function (options, callback) {
var AuthData = cos.getAuth({
Method: 'put',
Key: '1.txt'
});
callback({
Authorization: AuthData
});
}
});
putFile(initCos, done, assert);
});
});

group('getService()', function () {
Expand Down Expand Up @@ -4870,6 +4960,22 @@ group('downloadFile', function () {
done();
});
});
test('downloadFile() fileSize=0', function (done, assert) {
var Key = '0b.zip';
cos.downloadFile({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: Key,
FilePath: './' + Key, // 本地保存路径
ChunkSize: 1024 * 1024 * 8, // 分块大小
ParallelLimit: 5, // 分块并发数
RetryTimes: 3, // 分块失败重试次数
TaskId: '123', // 可以自己生成TaskId,用于取消下载
}, function (err, data) {
assert.ok(err);
done();
});
});
test('downloadFile() 小文件简单下载', function (done, assert) {
var Key = '1mb.zip';
var fileSize = 1024 * 1024 * 3;
Expand Down Expand Up @@ -4992,6 +5098,36 @@ group('downloadFile', function () {
}
});
});
test('downloadFile() 文件续传时远端文件已修改', function (done, assert) {
var Key = '50mb.zip';
var fileSize = 1024 * 1024 * 50;
var filePath = createFileSync(path.resolve(__dirname, Key), fileSize);
cos.sliceUploadFile({
Bucket: config.Bucket,
Region: config.Region,
Key: Key,
FilePath: filePath,
TrafficLimit: 819200,
}, function (err, data) {
if (err) {
done();
} else {
cos.downloadFile({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
Key: Key,
FilePath: './' + Key, // 本地保存路径
ChunkSize: 1024 * 1024 * 8, // 分块大小
ParallelLimit: 5, // 分块并发数
RetryTimes: 3, // 分块失败重试次数
TaskId: '123', // 可以自己生成TaskId,用于取消下载
}, function (err, data) {
assert.ok(!err);
done();
});
}
});
});
test('downloadFile() 下载归档文件', function (done, assert) {
var Key = '10mb.zip';
var fileSize = 1024 * 1024 * 10;
Expand Down