fix: track all configured DNS records
This commit is contained in:
parent
17ae9b4796
commit
7142c4cef8
4 changed files with 40 additions and 10 deletions
9
index.js
9
index.js
|
|
@ -96,7 +96,8 @@ async function getDnsRecords() {
|
|||
if (name === `${CONFIG.daDomain}.` || name === CONFIG.daDomain) {
|
||||
name = '';
|
||||
}
|
||||
records[name] = match[2];
|
||||
if (!records[name]) records[name] = [];
|
||||
records[name].push(match[2]);
|
||||
}
|
||||
}
|
||||
return records;
|
||||
|
|
@ -161,15 +162,15 @@ async function main() {
|
|||
for (const record of CONFIG.dnsRecords) {
|
||||
const name = record === CONFIG.daDomain ? '' : record;
|
||||
const label = name || '(apex)';
|
||||
const oldIp = dnsRecords[name] || dnsRecords[record];
|
||||
const oldIps = dnsRecords[name] || dnsRecords[record] || [];
|
||||
|
||||
try {
|
||||
if (oldIp) {
|
||||
for (const oldIp of oldIps) {
|
||||
await deleteDnsRecord(name, oldIp);
|
||||
}
|
||||
await addDnsRecord(name, currentIp);
|
||||
results.push(`✅ ${label}`);
|
||||
log(`Updated ${label}: ${oldIp || '(none)'} -> ${currentIp}`);
|
||||
log(`Updated ${label}: ${oldIps.join(', ') || '(none)'} -> ${currentIp}`);
|
||||
} catch (e) {
|
||||
results.push(`❌ ${label}: ${e.message}`);
|
||||
logError(`Failed to update ${label}: ${e.message}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue