sfun commited on
Commit
37ecab5
·
verified ·
1 Parent(s): 2e9046a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -68,7 +68,7 @@ async def extract_and_transform_proxies(input_text):
68
  transformed_proxies = []
69
 
70
  for proxy in proxies_list:
71
- if proxy.get('type') in ['ss', 'trojan']:
72
  name = proxy.get('name', '').strip()
73
  server = proxy.get('server', '').strip()
74
  port = str(proxy.get('port', '')).strip()
@@ -80,7 +80,7 @@ async def extract_and_transform_proxies(input_text):
80
  parts.append(f"encrypt-method={proxy['cipher'].strip()}")
81
  if 'password' in proxy:
82
  parts.append(f"password={proxy['password'].strip()}")
83
- elif proxy['type'] == 'trojan':
84
  if 'password' in proxy:
85
  parts.append(f"password={proxy['password'].strip()}")
86
  if 'sni' in proxy:
@@ -175,19 +175,17 @@ async def logging_middleware(request, handler):
175
  response = await handler(request)
176
  end_time = datetime.datetime.now()
177
 
178
- # 只有当 URL 参数存在且不为 '-' 时才记录日志
179
- if 'url' in request.query and request.query['url'] != '-':
180
- timestamp = end_time.strftime('%Y-%m-%d %H:%M:%S')
181
- client_ip = get_client_ip(request)
182
- target_url = request.query.get('url')
183
- no_cache = 'nocache' in request.query
184
- status_code = response.status
185
- proxy_count = response.headers.get('X-Proxy-Count', '0')
186
- cache_hit = "Hit" if response.headers.get('X-Cache-Hit') == 'True' else "Miss"
187
- cache_time = response.headers.get('X-Cache-Time', '-')
188
-
189
- log_message = f"{timestamp} - {client_ip} - \"GET /?url={target_url}{'&nocache' if no_cache else ''}\" - Status: {status_code} - Proxies: {proxy_count} - Cache: {cache_hit} - CacheTime: {cache_time} - NoCache: {'Yes' if no_cache else 'No'}"
190
- print(log_message, flush=True)
191
 
192
  return response
193
  except Exception as e:
 
68
  transformed_proxies = []
69
 
70
  for proxy in proxies_list:
71
+ if proxy.get('type') in ['ss', 'trojan', 'hysteria2']:
72
  name = proxy.get('name', '').strip()
73
  server = proxy.get('server', '').strip()
74
  port = str(proxy.get('port', '')).strip()
 
80
  parts.append(f"encrypt-method={proxy['cipher'].strip()}")
81
  if 'password' in proxy:
82
  parts.append(f"password={proxy['password'].strip()}")
83
+ elif proxy['type'] in ['trojan', 'hysteria2']:
84
  if 'password' in proxy:
85
  parts.append(f"password={proxy['password'].strip()}")
86
  if 'sni' in proxy:
 
175
  response = await handler(request)
176
  end_time = datetime.datetime.now()
177
 
178
+ timestamp = end_time.strftime('%Y-%m-%d %H:%M:%S')
179
+ client_ip = get_client_ip(request)
180
+ target_url = request.query.get('url', '-')
181
+ no_cache = 'nocache' in request.query
182
+ status_code = response.status
183
+ proxy_count = response.headers.get('X-Proxy-Count', '0')
184
+ cache_hit = "Hit" if response.headers.get('X-Cache-Hit') == 'True' else "Miss"
185
+ cache_time = response.headers.get('X-Cache-Time', '-')
186
+
187
+ log_message = f"{timestamp} - {client_ip} - \"GET /?url={target_url}{'&nocache' if no_cache else ''}\" - Status: {status_code} - Proxies: {proxy_count} - Cache: {cache_hit} - CacheTime: {cache_time} - NoCache: {'Yes' if no_cache else 'No'}"
188
+ print(log_message, flush=True)
 
 
189
 
190
  return response
191
  except Exception as e: