Skip to content

Commit

Permalink
Fix/substr key (#212)
Browse files Browse the repository at this point in the history
* fix: 默认截断 Key 中第一个斜杆

* fix: --other=优化下载异常处理

* fix: demo 优化
  • Loading branch information
livehigh authored Jul 10, 2024
1 parent c68ee53 commit 68ba295
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4369,7 +4369,6 @@ function getFileCompressTask() {
// 从 Bucket 里拆出 AppId
const AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);

createDataset();
// 创建数据集
function createDataset() {
const key = 'dataset'; // 固定值
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.14.2",
"version": "2.14.3",
"description": "cos nodejs sdk v5",
"main": "index.js",
"types": "index.d.ts",
Expand Down
3 changes: 0 additions & 3 deletions sdk/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,9 +1597,6 @@ function downloadFile(params, callback) {
Output: writeStream,
},
function (err, data) {
if (err && writeStream.writableFinished === false) {
writeStream.close && writeStream.close();
}
if (aborted) return;

// 处理错误和进度
Expand Down
3 changes: 3 additions & 0 deletions sdk/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4215,6 +4215,9 @@ function _submitRequest(params, callback) {
};

sender.on('error', function (err) {
if (params.outputStream) {
params.outputStream.close && params.outputStream.close();
}
markLastBytesWritten();
cb(util.error(err));
});
Expand Down
10 changes: 2 additions & 8 deletions sdk/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,8 @@ var apiWrapper = function (apiName, apiFn) {
delete params.AppId;
}
}
// 除了下列 api,如果 Key 是 / 开头,强制去掉第一个 /
var dontRemoveApi = ['sliceUploadFile', 'uploadFile', 'downloadFile', 'sliceCopyFile'];
if (
!self.options.UseRawKey &&
params.Key &&
params.Key.substr(0, 1) === '/' &&
!dontRemoveApi.includes(apiName)
) {
// 如果 Key 是 / 开头,强制去掉第一个 /
if (!self.options.UseRawKey && params.Key && params.Key.substr(0, 1) === '/') {
params.Key = params.Key.substr(1);
}
}
Expand Down

0 comments on commit 68ba295

Please sign in to comment.