Repository navigation
Expand file tree
/
Copy pathBaseConfigBuilder.js
More file actions
53 lines (45 loc) · 1.62 KB
/
Copy pathBaseConfigBuilder.js
File metadata and controls
53 lines (45 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { ProxyParser } from './ProxyParsers.js';
import { DeepCopy } from './utils.js';
export class BaseConfigBuilder {
constructor(inputString, baseConfig) {
this.inputString = inputString;
this.config = DeepCopy(baseConfig);
this.customRules = [];
}
async build() {
const customItems = await this.parseCustomItems();
this.addCustomItems(customItems);
this.addSelectors();
return this.formatConfig();
}
async parseCustomItems() {
const urls = this.inputString.split('\n').filter(url => url.trim() !== '');
const parsedItems = [];
for (const url of urls) {
const result = await ProxyParser.parse(url);
if (Array.isArray(result)) {
for (const subUrl of result) {
const subResult = await ProxyParser.parse(subUrl);
if (subResult) {
parsedItems.push(subResult);
}
}
} else if (result) {
parsedItems.push(result);
}
}
return parsedItems;
}
addCustomItems(customItems) {
// This method should be implemented in child classes
throw new Error('addCustomItems must be implemented in child class');
}
addSelectors() {
// This method should be implemented in child classes
throw new Error('addSelectors must be implemented in child class');
}
formatConfig() {
// This method should be implemented in child classes
throw new Error('formatConfig must be implemented in child class');
}
}