sfun commited on
Commit
dfd834e
1 Parent(s): 193d1cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -34,21 +34,34 @@ def extract_and_transform_proxies(input_text):
34
  name = proxy.get('name', '').strip()
35
  server = proxy.get('server', '').strip()
36
  port = str(proxy.get('port', '')).strip()
37
- cipher = proxy.get('cipher', '').strip()
38
- password = proxy.get('password', '').strip()
39
- udp = 'true' if proxy.get('udp') in [True, 'true', 'True'] else 'false'
 
 
 
 
 
 
40
 
41
- transformed = f"{name} = ss, {server}, {port}, encrypt-method={cipher}, password={password}, udp-relay={udp}"
42
  transformed_proxies.append(transformed)
 
43
  elif proxy.get('type') == 'trojan':
44
  name = proxy.get('name', '').strip()
45
  server = proxy.get('server', '').strip()
46
  port = str(proxy.get('port', '')).strip()
47
- password = proxy.get('password', '').strip()
48
- sni = proxy.get('sni', '').strip()
49
- skip_cert_verify = str(proxy.get('skip-cert-verify', '')).lower()
 
 
 
 
 
 
50
 
51
- transformed = f"{name} = trojan, {server}, {port}, password={password}, sni={sni}, skip-cert-verify={skip_cert_verify}"
52
  transformed_proxies.append(transformed)
53
 
54
  return "\n".join(transformed_proxies) if transformed_proxies else "未找到有效的SS或Trojan代理配置"
 
34
  name = proxy.get('name', '').strip()
35
  server = proxy.get('server', '').strip()
36
  port = str(proxy.get('port', '')).strip()
37
+
38
+ ss_parts = [f"{name} = ss, {server}, {port}"]
39
+
40
+ if 'cipher' in proxy:
41
+ ss_parts.append(f"encrypt-method={proxy['cipher'].strip()}")
42
+ if 'password' in proxy:
43
+ ss_parts.append(f"password={proxy['password'].strip()}")
44
+ if 'udp' in proxy:
45
+ ss_parts.append(f"udp-relay={'true' if proxy['udp'] in [True, 'true', 'True'] else 'false'}")
46
 
47
+ transformed = ", ".join(ss_parts)
48
  transformed_proxies.append(transformed)
49
+
50
  elif proxy.get('type') == 'trojan':
51
  name = proxy.get('name', '').strip()
52
  server = proxy.get('server', '').strip()
53
  port = str(proxy.get('port', '')).strip()
54
+
55
+ trojan_parts = [f"{name} = trojan, {server}, {port}"]
56
+
57
+ if 'password' in proxy:
58
+ trojan_parts.append(f"password={proxy['password'].strip()}")
59
+ if 'sni' in proxy:
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)
66
 
67
  return "\n".join(transformed_proxies) if transformed_proxies else "未找到有效的SS或Trojan代理配置"