tianlong12 commited on
Commit
c6d1186
·
verified ·
1 Parent(s): bf558a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -37
app.py CHANGED
@@ -1,50 +1,44 @@
1
  import requests
2
  from flask import Flask, Response, request
3
- import logging
4
 
5
  app = Flask(__name__)
6
- logging.basicConfig(level=logging.DEBUG)
7
 
8
  @app.route('/')
9
  def proxy_subscription():
10
- initial_url = 'http://testt.leov.asia/linuxdo/airport.php'
11
  try:
12
  # 获取订阅链接
13
- app.logger.debug(f"Requesting initial URL: {initial_url}")
14
- initial_response = requests.get(initial_url)
15
- initial_response.raise_for_status()
16
- subscription_url = initial_response.text.strip()
17
- app.logger.debug(f"Obtained subscription URL: {subscription_url}")
18
-
19
- # 构造模拟 Clash 的请求头
20
- headers = {
21
- 'User-Agent': 'Clash',
22
- 'Accept': 'application/vnd.clash.config'
23
- }
24
-
25
- # 获取订阅内容
26
- app.logger.debug(f"Requesting subscription content from: {subscription_url}")
27
- subscription_response = requests.get(subscription_url, headers=headers)
28
- subscription_response.raise_for_status()
29
-
30
- # 创建响应对象,完整返回内容
31
- resp = Response(subscription_response.content)
32
-
33
- # 复制所有头信息
34
- resp.headers.update(subscription_response.headers)
35
-
36
- app.logger.debug("Successfully processed subscription content")
37
- return resp
38
-
39
- except requests.RequestException as e:
40
- error_message = f"Request error: {str(e)}"
41
- app.logger.error(error_message)
42
- return error_message, 500
43
-
44
  except Exception as e:
45
- error_message = f"Unexpected error: {str(e)}"
46
- app.logger.error(error_message)
47
- return error_message, 500
48
 
49
  if __name__ == '__main__':
50
  app.run(host='0.0.0.0', port=7860)
 
1
  import requests
2
  from flask import Flask, Response, request
 
3
 
4
  app = Flask(__name__)
 
5
 
6
  @app.route('/')
7
  def proxy_subscription():
8
+ url = 'http://testt.leov.asia/linuxdo/airport.php'
9
  try:
10
  # 获取订阅链接
11
+ response = requests.get(url)
12
+ if response.status_code == 200:
13
+ subscription_url = response.text.strip()
14
+
15
+ # 构造模拟 Clash 的请求头
16
+ headers = {
17
+ 'User-Agent': 'Clash',
18
+ 'Accept': 'application/vnd.clash.config'
19
+ }
20
+
21
+ # 获取订阅内容
22
+ subscription_response = requests.get(subscription_url, headers=headers)
23
+ if subscription_response.status_code == 200:
24
+ content = subscription_response.text
25
+
26
+ # 创建响应对象
27
+ resp = Response(content, mimetype='text/plain')
28
+
29
+ # 复制重要的头信息
30
+ headers_to_copy = ['subscription-userinfo', 'profile-update-interval', 'content-disposition']
31
+ for header in headers_to_copy:
32
+ if header in subscription_response.headers:
33
+ resp.headers[header] = subscription_response.headers[header]
34
+
35
+ return resp
36
+ else:
37
+ return "Failed to fetch the subscription content", 500
38
+ else:
39
+ return "Failed to fetch the subscription link", 500
 
 
40
  except Exception as e:
41
+ return f"An error occurred: {str(e)}", 500
 
 
42
 
43
  if __name__ == '__main__':
44
  app.run(host='0.0.0.0', port=7860)