mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 05:40:29 +08:00
94 lines
3.9 KiB
JavaScript
94 lines
3.9 KiB
JavaScript
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const validateDomainAlive=require('../_virtual/validate-domain-alive.cjs'),fetchTextByLine=require('./lib/fetch-text-by-line.cjs'),processLine=require('./lib/process-line.cjs'),dir=require('./constants/dir.cjs'),require$$0=require('node:path'),require$$7=require('@henrygd/queue'),isDomainAlive=require('./lib/is-domain-alive.cjs'),require$$5=require('fdir');var hasRequiredValidateDomainAlive;
|
|
|
|
function requireValidateDomainAlive () {
|
|
if (hasRequiredValidateDomainAlive) return validateDomainAlive.__exports;
|
|
hasRequiredValidateDomainAlive = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
runAgainstDomainset: function() {
|
|
return runAgainstDomainset;
|
|
},
|
|
runAgainstRuleset: function() {
|
|
return runAgainstRuleset;
|
|
}
|
|
});
|
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.__require();
|
|
const _processline = /*@__PURE__*/ processLine.__require();
|
|
const _dir = /*@__PURE__*/ dir.__require();
|
|
const _nodepath = /*#__PURE__*/ _interop_require_default(require$$0);
|
|
const _queue = require$$7;
|
|
const _isdomainalive = /*@__PURE__*/ isDomainAlive.__require();
|
|
const _fdir = require$$5;
|
|
function _interop_require_default(obj) {
|
|
return obj && obj.__esModule ? obj : {
|
|
default: obj
|
|
};
|
|
}
|
|
const queue = (0, _queue.newQueue)(24);
|
|
const deadDomains = [];
|
|
function onDomain(args) {
|
|
if (!args[1]) {
|
|
deadDomains.push(args[0]);
|
|
}
|
|
}
|
|
(async ()=>{
|
|
const domainSets = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'domainset').withPromise();
|
|
const domainRules = await new _fdir.fdir().withFullPaths().crawl(_dir.SOURCE_DIR + _nodepath.default.sep + 'non_ip').withPromise();
|
|
await Promise.all([
|
|
...domainSets.map(runAgainstDomainset),
|
|
...domainRules.map(runAgainstRuleset)
|
|
]);
|
|
console.log();
|
|
console.log();
|
|
console.log(JSON.stringify(deadDomains));
|
|
})();
|
|
async function runAgainstRuleset(filepath) {
|
|
const extname = _nodepath.default.extname(filepath);
|
|
if (extname !== '.conf') {
|
|
console.log('[skip]', filepath);
|
|
return;
|
|
}
|
|
const promises = [];
|
|
for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){
|
|
const line = (0, _processline.processLine)(l);
|
|
if (!line) continue;
|
|
const [type, domain] = line.split(',');
|
|
switch(type){
|
|
case 'DOMAIN-SUFFIX':
|
|
case 'DOMAIN':
|
|
{
|
|
promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(domain, ()=>(0, _isdomainalive.isDomainAlive)(domain, type === 'DOMAIN-SUFFIX'))).then(onDomain));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
await Promise.all(promises);
|
|
console.log('[done]', filepath);
|
|
}
|
|
async function runAgainstDomainset(filepath) {
|
|
const extname = _nodepath.default.extname(filepath);
|
|
if (extname !== '.conf') {
|
|
console.log('[skip]', filepath);
|
|
return;
|
|
}
|
|
const promises = [];
|
|
for await (const l of (0, _fetchtextbyline.readFileByLine)(filepath)){
|
|
const line = (0, _processline.processLine)(l);
|
|
if (!line) continue;
|
|
promises.push(queue.add(()=>(0, _isdomainalive.keyedAsyncMutexWithQueue)(line, ()=>(0, _isdomainalive.isDomainAlive)(line, line[0] === '.'))).then(onDomain));
|
|
}
|
|
await Promise.all(promises);
|
|
console.log('[done]', filepath);
|
|
}
|
|
} (validateDomainAlive.__exports));
|
|
return validateDomainAlive.__exports;
|
|
}exports.__require=requireValidateDomainAlive; |