trashmail/node/index.js

57 lines
1.4 KiB
JavaScript

'use strict';
const git = require('simple-git'),
commander = require('commander'),
request = require('request-promise'),
fs = require('fs'),
redis = require("redis");
let pkg = require('./package.json'),
repos = require('./repositories.json'),
client = redis.createClient({
'host': 'redis',
'port': 6379
}),
saveList = [],
domainList = [];
client.on('error', (err) => {
console.error(`[x] ${err.toString()}`);
});
console.log(`[*] Gathering from ${repos.length} sources...`);
Promise.all(repos.map(d => request(d.url))).then((data) => {
repos.forEach((source) => {
console.log(` - ${source.url}`);
});
let tempList = data.join('\n').split('\n');
let domainList = [];
console.log(`[*] Creating domain list...`);
tempList.forEach((domain) => {
if (domain === '') {
return;
}
if (domainList[domain] === undefined) {
domainList[domain] = true;
}
});
domainList = Object.keys(domainList);
console.log(`[*] Found ${domainList.length} domains`);
console.log(`[*] Sorting by alphabet...`);
domainList = domainList.sort((a, b) => a !== b ? a < b ? -1 : 1 : 0);
console.log(`[*] Adding domains to cache...`)
domainList.forEach((domain) => {
client.hset('disposable', domain, true);
});
console.log(`[*] Done!`);
client.quit();
}).catch((err) => {
console.error(err.toString());
console.error(`URL: ${err.options.uri}`);
client.quit();
process.exit(1);
});