mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-15 18:15:56 +00:00
refactor(script): changes address cleanup
This commit is contained in:
2 files changed
+28
-9
No files matched your search
@@ -6,6 +6,12 @@ const { getDomains: gd } = require('../utils/get-domain');
|
|||||||
// Allow TXT records while publishing (for pcl validation)
|
// Allow TXT records while publishing (for pcl validation)
|
||||||
const getRecords = R.compose(R.toPairs, R.pick(VALID_RECORD_TYPES));
|
const getRecords = R.compose(R.toPairs, R.pick(VALID_RECORD_TYPES));
|
||||||
|
|
||||||
|
const address = (type, url) => {
|
||||||
|
if ('URL' === type) return `${url}`.replace(/\/$/g, '');
|
||||||
|
if ('TXT' === type) return url;
|
||||||
|
return (type === 'CNAME' ? `${url}`.toLowerCase() : `${url}`).replace(/[/.]$/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
const toHostList = R.chain(data => {
|
const toHostList = R.chain(data => {
|
||||||
const rs = getRecords(data.record);
|
const rs = getRecords(data.record);
|
||||||
|
|
||||||
@@ -13,7 +19,7 @@ const toHostList = R.chain(data => {
|
|||||||
(Array.isArray(urls) ? urls : [urls]).map((url, index) => ({
|
(Array.isArray(urls) ? urls : [urls]).map((url, index) => ({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
type: recordType,
|
type: recordType,
|
||||||
address: (recordType === 'CNAME' ? `${url}`.toLowerCase() : `${url}`).replace(/\/$/g, ''),
|
address: address(recordType, url),
|
||||||
ttl: TTL,
|
ttl: TTL,
|
||||||
...(recordType === 'MX' ? { priority: index + 20 } : {})
|
...(recordType === 'MX' ? { priority: index + 20 } : {})
|
||||||
}))
|
}))
|
||||||
|
|||||||
+21
-8
@@ -22,15 +22,27 @@ const recordToZone = ({ name, type, address, id, priority }) => ({
|
|||||||
...(type === 'TXT' ? { txtdata: address } : {}),
|
...(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 }) => ({
|
const zoneToRecord = ({
|
||||||
id,
|
name,
|
||||||
name: cleanName(name),
|
type,
|
||||||
type: `${type}`,
|
cname,
|
||||||
address: `${exchange || cname || address || record}`.replace(/\.$/g, '').toLowerCase(),
|
address,
|
||||||
priority: priority || preference,
|
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 }) => ({
|
const redirectionToRecord = ({ domain, destination }) => ({
|
||||||
id: domain,
|
id: domain,
|
||||||
name: cleanName(domain),
|
name: cleanName(domain),
|
||||||
@@ -121,6 +133,7 @@ const getDomainService = ({ cpanel }) => {
|
|||||||
const updateHosts = async hosts => {
|
const updateHosts = async hosts => {
|
||||||
const remoteHostList = await getHosts();
|
const remoteHostList = await getHosts();
|
||||||
const { add, remove } = diffRecords(remoteHostList, hosts);
|
const { add, remove } = diffRecords(remoteHostList, hosts);
|
||||||
|
console.log(`Adding ${add.length}; Removing ${remove.length}`)
|
||||||
|
|
||||||
await executeBatch([
|
await executeBatch([
|
||||||
...removeRecords(remove),
|
...removeRecords(remove),
|
||||||
|
|||||||
Reference in new issue
Block a user