sfun commited on
Commit
bfdbef9
1 Parent(s): dfd834e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -7,22 +7,23 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
7
  from urllib.parse import urlparse, parse_qs
8
 
9
  def extract_and_transform_proxies(input_text):
10
- proxies_match = re.search(r'proxies:\s*\n((?:[-\s]*{.*\n?)*)', input_text, re.MULTILINE)
11
- if not proxies_match:
12
- return "未找到proxies部分"
13
-
14
- proxies_text = proxies_match.group(1)
15
-
16
  try:
17
- proxies_list = yaml.safe_load(proxies_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  except yaml.YAMLError:
19
- proxies_list = []
20
- for proxy_str in re.findall(r'{(.*?)}', proxies_text, re.DOTALL):
21
- proxy_dict = {}
22
- for item in proxy_str.split(','):
23
- key, value = item.split(':', 1)
24
- proxy_dict[key.strip()] = value.strip()
25
- proxies_list.append(proxy_dict)
26
 
27
  if not proxies_list:
28
  return "未找到有效的代理配置"
@@ -60,6 +61,8 @@ def extract_and_transform_proxies(input_text):
60
  trojan_parts.append(f"sni={proxy['sni'].strip()}")
61
  if 'skip-cert-verify' in proxy:
62
  trojan_parts.append(f"skip-cert-verify={str(proxy['skip-cert-verify']).lower()}")
 
 
63
 
64
  transformed = ", ".join(trojan_parts)
65
  transformed_proxies.append(transformed)
 
7
  from urllib.parse import urlparse, parse_qs
8
 
9
  def extract_and_transform_proxies(input_text):
 
 
 
 
 
 
10
  try:
11
+ # 尝试解析整个输入作为YAML
12
+ data = yaml.safe_load(input_text)
13
+ if isinstance(data, dict) and 'proxies' in data:
14
+ proxies_list = data['proxies']
15
+ elif isinstance(data, list):
16
+ proxies_list = data
17
+ else:
18
+ # 如果不是预期的格式,尝试提取proxies部分
19
+ proxies_match = re.search(r'proxies:\s*\n((?:[-\s]*{.*\n?)*)', input_text, re.MULTILINE)
20
+ if proxies_match:
21
+ proxies_text = proxies_match.group(1)
22
+ proxies_list = yaml.safe_load(proxies_text)
23
+ else:
24
+ return "未找到有效的代理配置"
25
  except yaml.YAMLError:
26
+ return "YAML解析错误"
 
 
 
 
 
 
27
 
28
  if not proxies_list:
29
  return "未找到有效的代理配置"
 
61
  trojan_parts.append(f"sni={proxy['sni'].strip()}")
62
  if 'skip-cert-verify' in proxy:
63
  trojan_parts.append(f"skip-cert-verify={str(proxy['skip-cert-verify']).lower()}")
64
+ if 'udp' in proxy:
65
+ trojan_parts.append(f"udp={'true' if proxy['udp'] in [True, 'true', 'True'] else 'false'}")
66
 
67
  transformed = ", ".join(trojan_parts)
68
  transformed_proxies.append(transformed)