Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 11 |
try:
|
| 12 |
# 获取订阅链接
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
return error_message, 500
|
| 43 |
-
|
| 44 |
except Exception as e:
|
| 45 |
-
|
| 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)
|