mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Add build step to CDN domainset
This commit is contained in:
27
Build/lib/domain-deduper.js
Normal file
27
Build/lib/domain-deduper.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const Trie = require('./trie');
|
||||
|
||||
/**
|
||||
* @param {string[]} inputDomains
|
||||
*/
|
||||
const domainDeduper = (inputDomains) => {
|
||||
const trie = Trie.from(inputDomains);
|
||||
const sets = new Set(inputDomains);
|
||||
|
||||
for (let j = 0, len = inputDomains.length; j < len; j++) {
|
||||
const d = inputDomains[j];
|
||||
if (d[0] !== '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
trie.find(d, false).forEach(f => sets.delete(f));
|
||||
|
||||
const a = d.slice(1);
|
||||
if (trie.has(a)) {
|
||||
sets.delete(a);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(sets);
|
||||
};
|
||||
|
||||
module.exports.domainDeduper = domainDeduper;
|
||||
29
Build/lib/should-ignore-line.js
Normal file
29
Build/lib/should-ignore-line.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable camelcase -- cache index access */
|
||||
|
||||
/**
|
||||
* @param {string} line
|
||||
*/
|
||||
module.exports.shouldIgnoreLine = (line) => {
|
||||
if (line === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const line_0 = line[0];
|
||||
|
||||
if (
|
||||
line_0 === '#'
|
||||
|| line_0 === ' '
|
||||
|| line_0 === '\r'
|
||||
|| line_0 === '\n'
|
||||
|| line_0 === '!'
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed = line.trim();
|
||||
if (trimmed === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
};
|
||||
@@ -81,6 +81,7 @@ class Trie {
|
||||
$suffix = suffixStack.pop();
|
||||
node = nodeStack.pop();
|
||||
|
||||
// eslint-disable-next-line guard-for-in -- plain object
|
||||
for (k in node) {
|
||||
if (k === SENTINEL) {
|
||||
if (includeEqualWithSuffix) {
|
||||
@@ -89,7 +90,6 @@ class Trie {
|
||||
matches.push($suffix);
|
||||
}
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -161,8 +161,9 @@ class Trie {
|
||||
node = node[token];
|
||||
|
||||
// Prefix does not exist
|
||||
if (typeof node === 'undefined')
|
||||
if (typeof node === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Keeping track of a potential branch to prune
|
||||
if (toPrune !== null) {
|
||||
@@ -170,12 +171,9 @@ class Trie {
|
||||
toPrune = null;
|
||||
tokenToPrune = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Object.keys(node).length < 2) {
|
||||
toPrune = parent;
|
||||
tokenToPrune = token;
|
||||
}
|
||||
} else if (Object.keys(node).length < 2) {
|
||||
toPrune = parent;
|
||||
tokenToPrune = token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +204,9 @@ class Trie {
|
||||
token = suffix[i];
|
||||
node = node[token];
|
||||
|
||||
if (typeof node === 'undefined')
|
||||
if (typeof node === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return SENTINEL in node;
|
||||
@@ -217,7 +216,7 @@ class Trie {
|
||||
* @return {string[]}
|
||||
*/
|
||||
dump() {
|
||||
let node = this.root;
|
||||
const node = this.root;
|
||||
const nodeStack = [];
|
||||
const prefixStack = [];
|
||||
// Resolving initial prefix
|
||||
@@ -238,6 +237,7 @@ class Trie {
|
||||
currentNode = nodeStack.pop();
|
||||
currentPrefix = prefixStack.pop();
|
||||
|
||||
// eslint-disable-next-line guard-for-in -- plain object
|
||||
for (k in currentNode) {
|
||||
if (k === SENTINEL) {
|
||||
hasValue = true;
|
||||
|
||||
Reference in New Issue
Block a user