sfun commited on
Commit
7ed281d
1 Parent(s): 44e5a8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -54,7 +54,7 @@ async def extract_and_transform_proxies(input_text):
54
  # 检查是否是完整的配置文件格式
55
  if 'outbounds' in config:
56
  proxies_list = [outbound for outbound in config['outbounds']
57
- if outbound.get('type') in ['ss', 'trojan', 'hysteria2']]
58
  else:
59
  # 如果不是完整配置文件,假设它是代理列表
60
  proxies_list = config if isinstance(config, list) else [config]
@@ -83,7 +83,7 @@ async def extract_and_transform_proxies(input_text):
83
 
84
  for proxy in proxies_list:
85
  proxy_type = proxy.get('type')
86
- if proxy_type not in ['ss', 'trojan', 'hysteria2']:
87
  continue
88
 
89
  name = proxy.get('tag', '') or proxy.get('name', '')
@@ -91,15 +91,20 @@ async def extract_and_transform_proxies(input_text):
91
  server = proxy.get('server', '').strip()
92
  port = str(proxy.get('server_port', '') or proxy.get('port', '')).strip()
93
 
 
 
 
94
  parts = [f"{name} = {proxy_type}, {server}, {port}"]
95
 
96
  if proxy_type == 'ss':
97
- if 'cipher' in proxy:
98
- parts.append(f"encrypt-method={proxy['cipher'].strip()}")
99
- elif 'method' in proxy:
100
  parts.append(f"encrypt-method={proxy['method'].strip()}")
 
 
101
  if 'password' in proxy:
102
  parts.append(f"password={proxy['password'].strip()}")
 
 
103
  elif proxy_type in ['trojan', 'hysteria2']:
104
  if 'password' in proxy:
105
  parts.append(f"password={proxy['password'].strip()}")
 
54
  # 检查是否是完整的配置文件格式
55
  if 'outbounds' in config:
56
  proxies_list = [outbound for outbound in config['outbounds']
57
+ if outbound.get('type') in ['ss', 'shadowsocks', 'trojan', 'hysteria2']]
58
  else:
59
  # 如果不是完整配置文件,假设它是代理列表
60
  proxies_list = config if isinstance(config, list) else [config]
 
83
 
84
  for proxy in proxies_list:
85
  proxy_type = proxy.get('type')
86
+ if proxy_type not in ['ss', 'shadowsocks', 'trojan', 'hysteria2']:
87
  continue
88
 
89
  name = proxy.get('tag', '') or proxy.get('name', '')
 
91
  server = proxy.get('server', '').strip()
92
  port = str(proxy.get('server_port', '') or proxy.get('port', '')).strip()
93
 
94
+ if proxy_type == 'shadowsocks':
95
+ proxy_type = 'ss' # 将 shadowsocks 转换为 ss
96
+
97
  parts = [f"{name} = {proxy_type}, {server}, {port}"]
98
 
99
  if proxy_type == 'ss':
100
+ if 'method' in proxy:
 
 
101
  parts.append(f"encrypt-method={proxy['method'].strip()}")
102
+ elif 'cipher' in proxy:
103
+ parts.append(f"encrypt-method={proxy['cipher'].strip()}")
104
  if 'password' in proxy:
105
  parts.append(f"password={proxy['password'].strip()}")
106
+ # 为 ss 类型默认添加 udp-relay=true
107
+ parts.append("udp-relay=true")
108
  elif proxy_type in ['trojan', 'hysteria2']:
109
  if 'password' in proxy:
110
  parts.append(f"password={proxy['password'].strip()}")