Update app.py
Browse files
app.py
CHANGED
@@ -16,15 +16,22 @@ async def fetch_url(url, session):
|
|
16 |
async with session.get(url) as response:
|
17 |
return await response.text()
|
18 |
|
19 |
-
|
20 |
try:
|
|
|
21 |
data = yaml.safe_load(input_text)
|
22 |
if isinstance(data, dict) and 'proxies' in data:
|
23 |
proxies_list = data['proxies']
|
24 |
elif isinstance(data, list):
|
25 |
proxies_list = data
|
26 |
else:
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
except yaml.YAMLError:
|
29 |
return "YAML解析错误"
|
30 |
|
@@ -46,7 +53,7 @@ async def extract_and_transform_proxies(input_text):
|
|
46 |
if 'password' in proxy:
|
47 |
ss_parts.append(f"password={proxy['password'].strip()}")
|
48 |
if 'udp' in proxy:
|
49 |
-
ss_parts.append(f"udp-relay={'true' if proxy['udp'] else 'false'}")
|
50 |
|
51 |
transformed = ", ".join(ss_parts)
|
52 |
transformed_proxies.append(transformed)
|
@@ -65,7 +72,7 @@ async def extract_and_transform_proxies(input_text):
|
|
65 |
if 'skip-cert-verify' in proxy:
|
66 |
trojan_parts.append(f"skip-cert-verify={str(proxy['skip-cert-verify']).lower()}")
|
67 |
if 'udp' in proxy:
|
68 |
-
trojan_parts.append(f"udp={'true' if proxy['udp'] else 'false'}")
|
69 |
|
70 |
transformed = ", ".join(trojan_parts)
|
71 |
transformed_proxies.append(transformed)
|
|
|
16 |
async with session.get(url) as response:
|
17 |
return await response.text()
|
18 |
|
19 |
+
def extract_and_transform_proxies(input_text):
|
20 |
try:
|
21 |
+
# 尝试解析整个输入作为YAML
|
22 |
data = yaml.safe_load(input_text)
|
23 |
if isinstance(data, dict) and 'proxies' in data:
|
24 |
proxies_list = data['proxies']
|
25 |
elif isinstance(data, list):
|
26 |
proxies_list = data
|
27 |
else:
|
28 |
+
# 如果不是预期的格式,尝试提取proxies部分
|
29 |
+
proxies_match = re.search(r'proxies:\s*\n((?:[-\s]*{.*\n?)*)', input_text, re.MULTILINE)
|
30 |
+
if proxies_match:
|
31 |
+
proxies_text = proxies_match.group(1)
|
32 |
+
proxies_list = yaml.safe_load(proxies_text)
|
33 |
+
else:
|
34 |
+
return "未找到有效的代理配置"
|
35 |
except yaml.YAMLError:
|
36 |
return "YAML解析错误"
|
37 |
|
|
|
53 |
if 'password' in proxy:
|
54 |
ss_parts.append(f"password={proxy['password'].strip()}")
|
55 |
if 'udp' in proxy:
|
56 |
+
ss_parts.append(f"udp-relay={'true' if proxy['udp'] in [True, 'true', 'True'] else 'false'}")
|
57 |
|
58 |
transformed = ", ".join(ss_parts)
|
59 |
transformed_proxies.append(transformed)
|
|
|
72 |
if 'skip-cert-verify' in proxy:
|
73 |
trojan_parts.append(f"skip-cert-verify={str(proxy['skip-cert-verify']).lower()}")
|
74 |
if 'udp' in proxy:
|
75 |
+
trojan_parts.append(f"udp={'true' if proxy['udp'] in [True, 'true', 'True'] else 'false'}")
|
76 |
|
77 |
transformed = ", ".join(trojan_parts)
|
78 |
transformed_proxies.append(transformed)
|