Skip to content

Commit 0888c34

Browse files
Rong5180rongxwang
andauthored
fix: bug修复 (#271)
Co-authored-by: rongxwang <rongxwang@tencent.com>
1 parent 1a9470f commit 0888c34

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

src/modules/apigw/entities/application.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,38 @@ export default class AppEntity {
7070
// 2. bind api to app
7171
console.log(`Binding api(${apiId}) to application(${appDetail.id})`);
7272

73-
await this.request({
74-
Action: 'BindApiApp',
75-
ApiAppId: appDetail.id,
76-
ApiId: apiId,
77-
Environment: environment,
73+
// 绑定应用到API接口不支持可重入,第二次绑定会报错。
74+
// 解决方法是查询Api绑定的应用列表 已经绑定直接跳过,未绑定执行绑定流程
75+
const apiAppRes: {
76+
ApiAppApiSet: {
77+
ApiAppId: string;
78+
ApiAppName: string;
79+
ApiId: string;
80+
ServiceId: string;
81+
ApiRegion: string;
82+
EnvironmentName: string;
83+
AuthorizedTime: string;
84+
}[];
85+
} = await this.request({
86+
Action: 'DescribeApiBindApiAppsStatus',
7887
ServiceId: serviceId,
88+
ApiIds: [apiId],
89+
});
90+
const isBinded = apiAppRes.ApiAppApiSet.find((item) => {
91+
return item.ApiAppId === appDetail.id;
7992
});
8093

94+
if (!isBinded) {
95+
await this.request({
96+
Action: 'BindApiApp',
97+
ApiAppId: appDetail.id,
98+
ApiId: apiId,
99+
Environment: environment,
100+
ServiceId: serviceId,
101+
});
102+
console.log('BindApiApp success');
103+
}
104+
81105
return appDetail;
82106
}
83107

src/modules/cos/index.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,9 @@ export default class Cos {
524524
const items = traverseDirSync(inputs.dir);
525525

526526
let key;
527-
const promises: Promise<PutObjectResult>[] = [];
528-
items.forEach((item) => {
527+
let promises: Promise<PutObjectResult>[] = [];
528+
for (let i = 0; i < items.length; i++) {
529+
const item = items[i];
529530
// 如果是文件夹跳过
530531
if (item.stats.isDirectory()) {
531532
return;
@@ -547,11 +548,25 @@ export default class Cos {
547548
Body: fs.createReadStream(item.path),
548549
};
549550
promises.push(this.cosClient.putObject(itemParams));
550-
});
551-
try {
552-
await Promise.all(promises);
553-
} catch (err) {
554-
throw constructCosError(`API_COS_putObject`, err);
551+
// fs.createReadStream(item.path) 会一直打开文件,当文件超过1024会报错
552+
// 解决方案是分段请求,超过100请求一次,请求后会自动关闭文件
553+
if (promises.length >= 100) {
554+
try {
555+
await Promise.all(promises);
556+
promises = [];
557+
} catch (err) {
558+
throw constructCosError(`API_COS_putObject`, err);
559+
}
560+
}
561+
}
562+
// 循环结束后可能还有不足100的文件,此时需要单独再上传
563+
if (promises.length >= 1) {
564+
try {
565+
await Promise.all(promises);
566+
promises = [];
567+
} catch (err) {
568+
throw constructCosError(`API_COS_putObject`, err);
569+
}
555570
}
556571
} else if (inputs.file && (await fs.existsSync(inputs.file))) {
557572
/** 上传文件 */

src/modules/tag/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ export default class Tag {
247247
const oldTagVal = item.TagValue;
248248

249249
if (String(inputTag.TagValue) !== String(oldTagVal)) {
250+
// yml中 tagKey一样,tagVaule变化了 部署时会报错,解决方法是先解绑再绑定新的标签
251+
detachTags.push({
252+
TagKey: item.TagKey,
253+
});
250254
attachTags.push(inputTag);
251255
} else {
252256
leftTags.push(item);

0 commit comments

Comments
 (0)