import dnsPromises from 'dns/promises'; import { loadTencentCredentials, tc3Request } from './tencent-lib.mjs'; const CLB_HOST = 'lb-3g4yhjra-4f9thqng7wo1xvae.clb.nj-tencentclb.net'; async function dnsApi(cred, action, payload) { const json = await tc3Request({ ...cred, service: 'dnspod', region: 'ap-guangzhou', version: '2021-03-23', action, payload, }); if (json.Response?.Error) { throw new Error(`${action}: ${json.Response.Error.Code} ${json.Response.Error.Message}`); } return json.Response; } async function main() { const { secretId, secretKey } = loadTencentCredentials(); const cred = { secretId, secretKey }; const addrs = await dnsPromises.resolve4(CLB_HOST); console.log('CLB IPs', addrs); const vip = addrs[0]; const list = await dnsApi(cred, 'DescribeRecordList', { Domain: 'xdjchuanhui.com', Limit: 100 }); const apex = (list.RecordList || []).find((r) => r.Name === '@' && r.Type === 'CNAME'); console.log( 'apex', apex && { id: apex.RecordId, type: apex.Type, value: apex.Value } ); if (apex) { console.log('Change @ CNAME -> A', vip); await dnsApi(cred, 'ModifyRecord', { Domain: 'xdjchuanhui.com', RecordId: apex.RecordId, SubDomain: '@', RecordType: 'A', RecordLine: '默认', Value: vip, TTL: 600, }); console.log('@ fixed'); } else { const apexA = (list.RecordList || []).find((r) => r.Name === '@' && r.Type === 'A'); console.log('apex already', apexA && { type: apexA.Type, value: apexA.Value }); } const list2 = await dnsApi(cred, 'DescribeRecordList', { Domain: 'xdjchuanhui.com', Limit: 100 }); console.log( (list2.RecordList || []) .filter((r) => ['@', 'www'].includes(r.Name) && r.Type !== 'NS') .map((r) => ({ n: r.Name, t: r.Type, v: r.Value })) ); } main().catch((e) => { console.error(e); process.exit(1); });