Skip to content

fix: bug修复 #271

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
Feb 17, 2022
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
34 changes: 29 additions & 5 deletions src/modules/apigw/entities/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
29 changes: 22 additions & 7 deletions src/modules/cos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ export default class Cos {
const items = traverseDirSync(inputs.dir);

let key;
const promises: Promise<PutObjectResult>[] = [];
items.forEach((item) => {
let promises: Promise<PutObjectResult>[] = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
// 如果是文件夹跳过
if (item.stats.isDirectory()) {
return;
Expand All @@ -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))) {
/** 上传文件 */
Expand Down
4 changes: 4 additions & 0 deletions src/modules/tag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down