mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-18 06:26:28 +00:00
refactor(script): changes address cleanup
This commit is contained in:
+21
-8
@@ -22,15 +22,27 @@ const recordToZone = ({ name, type, address, id, priority }) => ({
|
||||
...(type === 'TXT' ? { txtdata: address } : {}),
|
||||
});
|
||||
|
||||
const cleanName = name => name === DOMAIN_DOMAIN ? '@' : `${name}`.replace(new RegExp(`\\.${DOMAIN_DOMAIN}\\.?$`), '').toLowerCase();
|
||||
const cleanName = name =>
|
||||
name === DOMAIN_DOMAIN ? '@' : `${name}`.replace(new RegExp(`\\.${DOMAIN_DOMAIN}\\.?$`), '').toLowerCase();
|
||||
|
||||
const zoneToRecord = ({ name, type, cname, address, priority, preference, exchange, record, line: id }) => ({
|
||||
id,
|
||||
name: cleanName(name),
|
||||
type: `${type}`,
|
||||
address: `${exchange || cname || address || record}`.replace(/\.$/g, '').toLowerCase(),
|
||||
priority: priority || preference,
|
||||
});
|
||||
const zoneToRecord = ({
|
||||
name,
|
||||
type,
|
||||
cname,
|
||||
address,
|
||||
priority,
|
||||
preference,
|
||||
exchange,
|
||||
record,
|
||||
line: id
|
||||
}) =>
|
||||
({
|
||||
id,
|
||||
name: cleanName(name),
|
||||
type: `${type}`,
|
||||
address: `${exchange || cname || address || record}`.replace(/\.$/g, '').toLowerCase(),
|
||||
priority: priority || preference,
|
||||
});
|
||||
const redirectionToRecord = ({ domain, destination }) => ({
|
||||
id: domain,
|
||||
name: cleanName(domain),
|
||||
@@ -121,6 +133,7 @@ const getDomainService = ({ cpanel }) => {
|
||||
const updateHosts = async hosts => {
|
||||
const remoteHostList = await getHosts();
|
||||
const { add, remove } = diffRecords(remoteHostList, hosts);
|
||||
console.log(`Adding ${add.length}; Removing ${remove.length}`)
|
||||
|
||||
await executeBatch([
|
||||
...removeRecords(remove),
|
||||
|
||||
Reference in New Issue
Block a user