Aggregates fetching of records from zone and redirections

This commit is contained in:
Akshay Nair
2020-10-11 17:50:29 +05:30
parent fa9ad8baef
commit 49e8dd7fd0
3 changed files with 62 additions and 23 deletions
+15 -5
View File
@@ -1,19 +1,29 @@
const R = require('ramda');
const { cpanel } = require('./lib/cpanel');
const {DOMAIN_DOMAIN} = require('./constants');
const flattenPromise = xs => Promise.all(xs);
const getDomainService = ({ cpanel }) => {
let hostList = [];
const fetchZoneRecords = () => cpanel.fetchZoneRecords().then(R.map(host => ({
...host,
name: `${host.name}`,
type: `${host.type}`,
address: `${host.cname || host.address}`.replace(/\.$/g, ''),
})));
const fetchRedirections = () => cpanel.fetchRedirections().then(R.map(host => ({
name: `${host.domain}`.replace('.' + DOMAIN_DOMAIN, ''),
type: 'URL',
address: `${host.destination}`,
})));
const getHosts = async () => {
if (hostList.length) return hostList;
const list = await cpanel.fetchZoneRecords()
.then(R.map(host => R.omit(['Name', 'Type'], {
...host,
address: `${host.cname || host.address}`.replace(/\.$/g, ''),
})));
const list = await Promise.all([fetchZoneRecords(), fetchRedirections()]).then(R.flatten);
hostList = list;
return list;
+4 -1
View File
@@ -51,7 +51,10 @@ const CpanelClient = (options) => {
// {}
// -> { }
fetchRedirections: uapi('Mime', 'list_redirects'),
fetchRedirections: R.compose(
p => p.then(R.pathOr([], ['data'])),
uapi('Mime', 'list_redirects'),
),
};
};