mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-20 06:23:50 +00:00
Aggregates fetching of records from zone and redirections
This commit is contained in:
+15
-5
@@ -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
@@ -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'),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user