From 0888c34d4694eff71630caa49ad5f5494f55d6c0 Mon Sep 17 00:00:00 2001 From: Rong <58057861+Rong5180@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:10:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20bug=E4=BF=AE=E5=A4=8D=20(#271)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: rongxwang --- src/modules/apigw/entities/application.ts | 34 +++++++++++++++++++---- src/modules/cos/index.ts | 29 ++++++++++++++----- src/modules/tag/index.ts | 4 +++ 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/modules/apigw/entities/application.ts b/src/modules/apigw/entities/application.ts index c26f8224..1e3bc239 100644 --- a/src/modules/apigw/entities/application.ts +++ b/src/modules/apigw/entities/application.ts @@ -70,14 +70,38 @@ export default class AppEntity { // 2. bind api to app console.log(`Binding api(${apiId}) to application(${appDetail.id})`); - await this.request({ - Action: 'BindApiApp', - ApiAppId: appDetail.id, - ApiId: apiId, - Environment: environment, + // 绑定应用到API接口不支持可重入,第二次绑定会报错。 + // 解决方法是查询Api绑定的应用列表 已经绑定直接跳过,未绑定执行绑定流程 + const apiAppRes: { + ApiAppApiSet: { + ApiAppId: string; + ApiAppName: string; + ApiId: string; + ServiceId: string; + ApiRegion: string; + EnvironmentName: string; + AuthorizedTime: string; + }[]; + } = await this.request({ + Action: 'DescribeApiBindApiAppsStatus', ServiceId: serviceId, + ApiIds: [apiId], + }); + const isBinded = apiAppRes.ApiAppApiSet.find((item) => { + return item.ApiAppId === appDetail.id; }); + if (!isBinded) { + await this.request({ + Action: 'BindApiApp', + ApiAppId: appDetail.id, + ApiId: apiId, + Environment: environment, + ServiceId: serviceId, + }); + console.log('BindApiApp success'); + } + return appDetail; } diff --git a/src/modules/cos/index.ts b/src/modules/cos/index.ts index f96bc4e9..f59581a8 100644 --- a/src/modules/cos/index.ts +++ b/src/modules/cos/index.ts @@ -524,8 +524,9 @@ export default class Cos { const items = traverseDirSync(inputs.dir); let key; - const promises: Promise[] = []; - items.forEach((item) => { + let promises: Promise[] = []; + for (let i = 0; i < items.length; i++) { + const item = items[i]; // 如果是文件夹跳过 if (item.stats.isDirectory()) { return; @@ -547,11 +548,25 @@ export default class Cos { Body: fs.createReadStream(item.path), }; promises.push(this.cosClient.putObject(itemParams)); - }); - try { - await Promise.all(promises); - } catch (err) { - throw constructCosError(`API_COS_putObject`, err); + // fs.createReadStream(item.path) 会一直打开文件,当文件超过1024会报错 + // 解决方案是分段请求,超过100请求一次,请求后会自动关闭文件 + if (promises.length >= 100) { + try { + await Promise.all(promises); + promises = []; + } catch (err) { + throw constructCosError(`API_COS_putObject`, err); + } + } + } + // 循环结束后可能还有不足100的文件,此时需要单独再上传 + if (promises.length >= 1) { + try { + await Promise.all(promises); + promises = []; + } catch (err) { + throw constructCosError(`API_COS_putObject`, err); + } } } else if (inputs.file && (await fs.existsSync(inputs.file))) { /** 上传文件 */ diff --git a/src/modules/tag/index.ts b/src/modules/tag/index.ts index 22a5b77c..3907f06b 100644 --- a/src/modules/tag/index.ts +++ b/src/modules/tag/index.ts @@ -247,6 +247,10 @@ export default class Tag { const oldTagVal = item.TagValue; if (String(inputTag.TagValue) !== String(oldTagVal)) { + // yml中 tagKey一样,tagVaule变化了 部署时会报错,解决方法是先解绑再绑定新的标签 + detachTags.push({ + TagKey: item.TagKey, + }); attachTags.push(inputTag); } else { leftTags.push(item); From 213a25ced58b644c4d6bdd706241ac6e14c1e655 Mon Sep 17 00:00:00 2001 From: slsplus Date: Thu, 17 Feb 2022 11:11:37 +0000 Subject: [PATCH 2/2] chore(release): version 2.23.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [2.23.2](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.23.1...v2.23.2) (2022-02-17) ### Bug Fixes * bug修复 ([#271](https://github.com/serverless-tencent/tencent-component-toolkit/issues/271)) ([0888c34](https://github.com/serverless-tencent/tencent-component-toolkit/commit/0888c34d4694eff71630caa49ad5f5494f55d6c0)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 417792b9..97c17219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.23.2](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.23.1...v2.23.2) (2022-02-17) + + +### Bug Fixes + +* bug修复 ([#271](https://github.com/serverless-tencent/tencent-component-toolkit/issues/271)) ([0888c34](https://github.com/serverless-tencent/tencent-component-toolkit/commit/0888c34d4694eff71630caa49ad5f5494f55d6c0)) + ## [2.23.1](https://github.com/serverless-tencent/tencent-component-toolkit/compare/v2.23.0...v2.23.1) (2022-01-11) diff --git a/package.json b/package.json index 4b4db07f..833e1309 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tencent-component-toolkit", - "version": "2.23.1", + "version": "2.23.2", "description": "Tencent component toolkit", "main": "lib/index.js", "types": "lib/index.d.ts",