toml 批量端口

This commit is contained in:
刘嘉伟 2024-09-07 17:01:49 +08:00
parent e0b3f6e7a7
commit dbfceb9550
2 changed files with 26 additions and 6 deletions

View File

@ -40,19 +40,36 @@ const getFrpcVersionWorkerPath = (
*/ */
export const genTomlConfig = (config: FrpConfig, proxys: Proxy[]) => { export const genTomlConfig = (config: FrpConfig, proxys: Proxy[]) => {
const proxyToml = proxys.map(m => { const proxyToml = proxys.map(m => {
const rangePort =
(m.localPort.indexOf("-") !== -1 || m.localPort.indexOf(",") !== -1) &&
(m.type === "tcp" || m.type === "udp");
let toml = ` let toml = `
${
rangePort
? `{{- range $_, $v := parseNumberRangePair "${m.localPort}" "${m.remotePort}" }}`
: ""
}
[[${m.type === "stcp" && m.stcpModel === "visitors" ? "visitors" : "proxies"}]] [[${m.type === "stcp" && m.stcpModel === "visitors" ? "visitors" : "proxies"}]]
name = "${m.name}" ${rangePort ? "" : `name = "${m.name}"\n`}
type = "${m.type}" type = "${m.type}"
`; `;
switch (m.type) { switch (m.type) {
case "tcp": case "tcp":
case "udp": case "udp":
toml += ` if (rangePort) {
toml += `
name = "${m.name}-{{ $v.First }}"
localPort = {{ $v.First }}
remotePort = {{ $v.Second }}
`;
} else {
toml += `
localIP = "${m.localIp}" localIP = "${m.localIp}"
localPort = "${m.localPort}" localPort = ${m.localPort}
remotePort = "${m.remotePort}" remotePort = ${m.remotePort}
`; `;
}
break; break;
case "http": case "http":
case "https": case "https":
@ -84,6 +101,9 @@ secretKey="${m.secretKey}"
break; break;
} }
if (rangePort) {
toml += `{{- end }}`;
}
return toml; return toml;
}); });
const toml = ` const toml = `

4
types/global.d.ts vendored
View File

@ -18,8 +18,8 @@ declare global {
name: string; name: string;
type: string; type: string;
localIp: string; localIp: string;
localPort: number; localPort: string;
remotePort: number; remotePort: string;
customDomains: string[]; customDomains: string[];
stcpModel: string; stcpModel: string;
serverName: string; serverName: string;