✨ toml 批量端口
This commit is contained in:
parent
e0b3f6e7a7
commit
dbfceb9550
@ -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
4
types/global.d.ts
vendored
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user