Skip to content

Commit 6048c96

Browse files
CopilotBlankll
andcommitted
refactor: Add multi-lang support and remove unnecessary comments
Applied coding guidelines: 1. Added multi-lang support for all log messages in event, function, and bucket resources 2. Removed unnecessary comments throughout the codebase 3. Refactored dnsOperations.ts to use functional approach with const arrow functions Changes: - Added lang keys to en.ts and zh-CN.ts for API Gateway, Functions, and Buckets - Updated apigwResource.ts to use lang.__() for all logger calls - Updated fc3Resource.ts to use lang.__() for all logger calls - Updated ossResource.ts to use lang.__() for all logger calls - Refactored dnsOperations.ts from function returning object to const arrow functions with proper composition - Removed unnecessary comments that explained obvious code behavior All messages now support English and Chinese localization. Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
1 parent a1dc322 commit 6048c96

File tree

6 files changed

+105
-124
lines changed

6 files changed

+105
-124
lines changed

src/common/aliyunClient/dnsOperations.ts

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as dns from '@alicloud/alidns20150109';
33

44
type DnsSdkClient = DnsClient;
55

6-
/**
7-
* DNS record configuration
8-
*/
96
export type DnsRecordConfig = {
107
domainName: string;
118
rr: string;
@@ -14,9 +11,6 @@ export type DnsRecordConfig = {
1411
ttl?: number;
1512
};
1613

17-
/**
18-
* DNS record info
19-
*/
2014
export type DnsRecordInfo = {
2115
recordId?: string;
2216
domainName?: string;
@@ -27,76 +21,78 @@ export type DnsRecordInfo = {
2721
status?: string;
2822
};
2923

30-
/**
31-
* Create DNS operations
32-
*/
33-
export function createDnsOperations(dnsClient: DnsSdkClient) {
34-
const operations = {
35-
/**
36-
* Add a DNS record
37-
*/
38-
addDomainRecord: async (config: DnsRecordConfig): Promise<string> => {
39-
const request = new dns.AddDomainRecordRequest({
40-
domainName: config.domainName,
41-
RR: config.rr,
42-
type: config.type,
43-
value: config.value,
44-
TTL: config.ttl || 600,
45-
});
24+
export type DnsOperations = {
25+
addDomainRecord: (config: DnsRecordConfig) => Promise<string>;
26+
deleteDomainRecord: (recordId: string) => Promise<void>;
27+
describeDomainRecords: (domainName: string, rrKeyWord?: string) => Promise<Array<DnsRecordInfo>>;
28+
checkDomainRecordExists: (domainName: string, rr: string) => Promise<boolean>;
29+
};
30+
31+
const addDomainRecord = (dnsClient: DnsSdkClient) => async (
32+
config: DnsRecordConfig,
33+
): Promise<string> => {
34+
const request = new dns.AddDomainRecordRequest({
35+
domainName: config.domainName,
36+
RR: config.rr,
37+
type: config.type,
38+
value: config.value,
39+
TTL: config.ttl || 600,
40+
});
41+
42+
const response = await dnsClient.addDomainRecord(request);
43+
return response.body?.recordId || '';
44+
};
4645

47-
const response = await dnsClient.addDomainRecord(request);
48-
return response.body?.recordId || '';
49-
},
46+
const deleteDomainRecord = (dnsClient: DnsSdkClient) => async (recordId: string): Promise<void> => {
47+
const request = new dns.DeleteDomainRecordRequest({
48+
recordId,
49+
});
5050

51-
/**
52-
* Delete a DNS record
53-
*/
54-
deleteDomainRecord: async (recordId: string): Promise<void> => {
55-
const request = new dns.DeleteDomainRecordRequest({
56-
recordId,
57-
});
51+
await dnsClient.deleteDomainRecord(request);
52+
};
5853

59-
await dnsClient.deleteDomainRecord(request);
60-
},
54+
const describeDomainRecords = (dnsClient: DnsSdkClient) => async (
55+
domainName: string,
56+
rrKeyWord?: string,
57+
): Promise<Array<DnsRecordInfo>> => {
58+
const request = new dns.DescribeDomainRecordsRequest({
59+
domainName,
60+
RRKeyWord: rrKeyWord,
61+
});
6162

62-
/**
63-
* Describe domain records
64-
*/
65-
describeDomainRecords: async (
66-
domainName: string,
67-
rrKeyWord?: string,
68-
): Promise<Array<DnsRecordInfo>> => {
69-
const request = new dns.DescribeDomainRecordsRequest({
70-
domainName,
71-
RRKeyWord: rrKeyWord,
72-
});
63+
const response = await dnsClient.describeDomainRecords(request);
64+
const records = response.body?.domainRecords?.record || [];
7365

74-
const response = await dnsClient.describeDomainRecords(request);
75-
const records = response.body?.domainRecords?.record || [];
66+
return records.map((record: dns.DescribeDomainRecordsResponseBodyDomainRecordsRecord) => ({
67+
recordId: record.recordId,
68+
domainName: record.domainName,
69+
rr: record.RR,
70+
type: record.type,
71+
value: record.value,
72+
ttl: record.TTL,
73+
status: record.status,
74+
}));
75+
};
7676

77-
return records.map((record: dns.DescribeDomainRecordsResponseBodyDomainRecordsRecord) => ({
78-
recordId: record.recordId,
79-
domainName: record.domainName,
80-
rr: record.RR,
81-
type: record.type,
82-
value: record.value,
83-
ttl: record.TTL,
84-
status: record.status,
85-
}));
86-
},
77+
const checkDomainRecordExists = (
78+
describeFn: (domainName: string, rrKeyWord?: string) => Promise<Array<DnsRecordInfo>>,
79+
) => async (domainName: string, rr: string): Promise<boolean> => {
80+
try {
81+
const records = await describeFn(domainName, rr);
82+
return records.some((record) => record.rr === rr);
83+
} catch {
84+
return false;
85+
}
86+
};
8787

88-
/**
89-
* Check if a DNS record exists
90-
*/
91-
checkDomainRecordExists: async (domainName: string, rr: string): Promise<boolean> => {
92-
try {
93-
const records = await operations.describeDomainRecords(domainName, rr);
94-
return records.some((record) => record.rr === rr);
95-
} catch {
96-
return false;
97-
}
98-
},
88+
export const createDnsOperations = (dnsClient: DnsSdkClient): DnsOperations => {
89+
const describe = describeDomainRecords(dnsClient);
90+
91+
return {
92+
addDomainRecord: addDomainRecord(dnsClient),
93+
deleteDomainRecord: deleteDomainRecord(dnsClient),
94+
describeDomainRecords: describe,
95+
checkDomainRecordExists: checkDomainRecordExists(describe),
9996
};
97+
};
10098

101-
return operations;
102-
}

src/lang/en.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,20 @@ export const en = {
214214
LOCK_TIME_AGO_MINUTES: '{{minutes}} minutes ago',
215215
LOCK_TIME_AGO_ONE_HOUR: '1 hour ago',
216216
LOCK_TIME_AGO_HOURS: '{{hours}} hours ago',
217+
218+
// API Gateway messages
219+
APIGW_GROUP_FOUND_REUSING: 'Found existing API Group: {{groupName}}, will reuse it',
220+
APIGW_DOMAIN_BINDING_FAILED: 'Failed to bind custom domain: {{error}}',
221+
APIGW_GROUP_APIS_CREATED_DOMAIN_FAILED:
222+
'API Gateway group and APIs created successfully, but domain binding failed',
223+
APIGW_STATE_SAVED_RETRY: 'State has been saved. You can retry or fix domain configuration',
224+
225+
// Function resource messages
226+
FC3_DEPENDENT_RESOURCES_TRACKED:
227+
'Dependent resources (SLS, RAM, Security Group, NAS) are tracked in state',
228+
FC3_CAN_RETRY_DEPLOYMENT:
229+
'You can retry deployment - the system will reuse existing dependent resources',
230+
231+
// Bucket resource messages
232+
OSS_BUCKET_TRACKED_CAN_RETRY: 'Bucket is tracked in state, you can retry deployment to upload files',
217233
};

src/lang/zh-CN.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,17 @@ export const zhCN = {
176176
PARTIAL_FAILURE_NEXT_STEPS:
177177
'后续步骤: 1) 查看上面的错误, 2) 修复配置问题, 3) 再次运行 deploy 继续。',
178178
STATE_PERSISTED_AFTER_OPERATION: '{{action}} {{resourceId}} 后状态已持久化',
179+
180+
// API Gateway messages
181+
APIGW_GROUP_FOUND_REUSING: '找到现有 API 分组: {{groupName}},将复用它',
182+
APIGW_DOMAIN_BINDING_FAILED: '绑定自定义域名失败: {{error}}',
183+
APIGW_GROUP_APIS_CREATED_DOMAIN_FAILED: 'API 网关分组和 API 创建成功,但域名绑定失败',
184+
APIGW_STATE_SAVED_RETRY: '状态已保存。您可以重试或修复域名配置',
185+
186+
// Function resource messages
187+
FC3_DEPENDENT_RESOURCES_TRACKED: '依赖资源(SLS、RAM、安全组、NAS)已在状态中跟踪',
188+
FC3_CAN_RETRY_DEPLOYMENT: '您可以重试部署 - 系统将复用现有的依赖资源',
189+
190+
// Bucket resource messages
191+
OSS_BUCKET_TRACKED_CAN_RETRY: '存储桶已在状态中跟踪,您可以重试部署以上传文件',
179192
};

0 commit comments

Comments
 (0)