From 68ba295a236a2cfc56419a43c96a881c5c7dcab0 Mon Sep 17 00:00:00 2001 From: chrisftian Date: Wed, 10 Jul 2024 17:44:44 +0800 Subject: [PATCH] Fix/substr key (#212) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 默认截断 Key 中第一个斜杆 * fix: --other=优化下载异常处理 * fix: demo 优化 --- demo/demo.js | 1 - package.json | 2 +- sdk/advance.js | 3 --- sdk/base.js | 3 +++ sdk/util.js | 10 ++-------- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index d6d23e0..1f761cb 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -4369,7 +4369,6 @@ function getFileCompressTask() { // 从 Bucket 里拆出 AppId const AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1); -createDataset(); // 创建数据集 function createDataset() { const key = 'dataset'; // 固定值 diff --git a/package.json b/package.json index a06e9bd..cd511de 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/sdk/advance.js b/sdk/advance.js index a0d7907..e882fb4 100644 --- a/sdk/advance.js +++ b/sdk/advance.js @@ -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; // 处理错误和进度 diff --git a/sdk/base.js b/sdk/base.js index ff9bb53..f32fbe2 100644 --- a/sdk/base.js +++ b/sdk/base.js @@ -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)); }); diff --git a/sdk/util.js b/sdk/util.js index ebe4558..566dae2 100644 --- a/sdk/util.js +++ b/sdk/util.js @@ -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); } }