Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
72 lines (62 loc) · 1.86 KB
/
Copy pathmain.ts
File metadata and controls
72 lines (62 loc) · 1.86 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { join } from "@std/path/join";
import { BuildOptions } from "./src/config.ts";
import { convertWireGuardToSingBox } from "./src/convert.ts";
import { buildConfig } from "./src/index.ts";
import { startBox } from "./src/launcher.ts";
import { Route, RouteAcceptor } from "./src/routes.ts";
const inDir = ".";
const profileDir = "profile";
const workdirPath = "workdir";
const configDir = join(inDir, "config");
const rulesSearchDirs = ["rules", join(inDir, "rules")];
const routeDir = join(inDir, "route");
const inputFile = join(inDir, "config.json");
const outputFile = join(workdirPath, "config.json");
let l3BridgeEnabled: boolean = false;
async function main() {
l3BridgeEnabled = Deno.build.os === "windows";
const options: BuildOptions = {
configDir,
rulesSearchDirs: rulesSearchDirs,
routeDir: routeDir,
inputFile,
workDir: workdirPath,
outputFile,
proxyOutbound: "geo-ru",
directOutbound: "direct",
dnsDirectServer: "dns-direct",
};
if (l3BridgeEnabled) {
options.l3DirectOutbound = "l3-direct";
}
const builtinOutbounds = ["direct", "block"];
const overrideRoutes: Record<string, string> = {
// "geo-fi": "WARPw26312.conf",
// "geo-nl": "WARPw46075.conf",
// "geo-de": "WARPw04621.conf",
// "geo-pl": "WARPw46972.conf",
// "geo-de-alt": "AWGw35194.conf",
// "proxy": "WARPw05841.conf"
};
buildConfig(options, ((entry, config) => {
if (builtinOutbounds.includes(entry)) {
return new Route("route", entry);
}
let fileName = overrideRoutes[entry];
if (!fileName || fileName.trim().length === 0) {
fileName = `${entry}.conf`;
}
if (
!convertWireGuardToSingBox(
entry,
join(profileDir, fileName),
config,
)
) {
return null;
}
return new Route("route", entry);
}) as RouteAcceptor);
await startBox(workdirPath);
}
await main();