Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mololab
GitHub Repository: mololab/json-translator
Path: blob/master/src/core/proxy_file.ts
235 views
1
import * as fs from 'fs';
2
import { error, success } from '../utils/console';
3
4
export async function readProxyFile(file_path: string) {
5
const confs = {
6
checkerRX: /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}:(\d){1,}$/,
7
};
8
const data = await fs.promises.readFile(file_path, 'utf8');
9
if (!data) {
10
error('proxy file is empty!');
11
return;
12
}
13
14
let proxyList = data.split(/\r?\n/);
15
16
proxyList = proxyList.filter(proxy_item => confs.checkerRX.test(proxy_item));
17
18
success(`\n---------------- Proxy Mode ----------------\n`);
19
global.proxyList = proxyList;
20
}
21
22