From dbfceb9550c37358ac64cde93dd0e57bc38a414e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Sat, 7 Sep 2024 17:01:49 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20toml=20=E6=89=B9=E9=87=8F=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/frpc.ts | 28 ++++++++++++++++++++++++---- types/global.d.ts | 4 ++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/electron/api/frpc.ts b/electron/api/frpc.ts index 1096974..e7dcc43 100644 --- a/electron/api/frpc.ts +++ b/electron/api/frpc.ts @@ -40,19 +40,36 @@ const getFrpcVersionWorkerPath = ( */ export const genTomlConfig = (config: FrpConfig, proxys: Proxy[]) => { const proxyToml = proxys.map(m => { + const rangePort = + (m.localPort.indexOf("-") !== -1 || m.localPort.indexOf(",") !== -1) && + (m.type === "tcp" || m.type === "udp"); let toml = ` +${ + rangePort + ? `{{- range $_, $v := parseNumberRangePair "${m.localPort}" "${m.remotePort}" }}` + : "" +} [[${m.type === "stcp" && m.stcpModel === "visitors" ? "visitors" : "proxies"}]] -name = "${m.name}" +${rangePort ? "" : `name = "${m.name}"\n`} type = "${m.type}" `; + switch (m.type) { case "tcp": case "udp": - toml += ` + if (rangePort) { + toml += ` +name = "${m.name}-{{ $v.First }}" +localPort = {{ $v.First }} +remotePort = {{ $v.Second }} + `; + } else { + toml += ` localIP = "${m.localIp}" -localPort = "${m.localPort}" -remotePort = "${m.remotePort}" +localPort = ${m.localPort} +remotePort = ${m.remotePort} `; + } break; case "http": case "https": @@ -84,6 +101,9 @@ secretKey="${m.secretKey}" break; } + if (rangePort) { + toml += `{{- end }}`; + } return toml; }); const toml = ` diff --git a/types/global.d.ts b/types/global.d.ts index cd42115..61d65f0 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -18,8 +18,8 @@ declare global { name: string; type: string; localIp: string; - localPort: number; - remotePort: number; + localPort: string; + remotePort: string; customDomains: string[]; stcpModel: string; serverName: string;