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[]) => {
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 = `

4
types/global.d.ts vendored
View File

@ -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;