megatrump commited on
Commit
28832ec
·
1 Parent(s): 849d277

隐秘的转换订阅链接

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. Dockerfile +2 -1
  3. app.py +37 -8
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ test.sh
Dockerfile CHANGED
@@ -1,4 +1,5 @@
1
- ARG MODEL_REPO_NAME
 
2
 
3
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm
4
 
 
1
+ ARG API_KEY
2
+ ARG SUBSCRIBE_URLS
3
 
4
  FROM ghcr.io/astral-sh/uv:python3.12-bookworm
5
 
app.py CHANGED
@@ -1,20 +1,49 @@
1
-
2
-
3
  import os
4
  import sys
5
  import requests
6
- from flask import Flask
7
  from urllib.parse import urlencode
8
  from asgiref.wsgi import WsgiToAsgi
9
 
10
  app = Flask(__name__)
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  @app.get("/")
13
  def read_root():
14
- s: str = str(os.environ.get('MODEL_REPO_NAME'))
15
- resp = requests.get("http://127.0.0.1:25500/version")
16
- resp.raise_for_status()
17
- data = resp.text
18
- return {"Hello": f"World! {data} + {s}"}
19
 
20
  asgi_app = WsgiToAsgi(app)
 
 
 
1
  import os
2
  import sys
3
  import requests
4
+ from flask import Flask, Response, request
5
  from urllib.parse import urlencode
6
  from asgiref.wsgi import WsgiToAsgi
7
 
8
  app = Flask(__name__)
9
 
10
+ # 从环境变量中获取密钥
11
+ API_KEY = os.environ.get('API_KEY')
12
+ SUBSCRIBE_URLS = os.environ.get('SUBSCRIBE_URLS') # 存储真实URL的变量
13
+
14
+ @app.get("/getsub")
15
+ def read_subscribe():
16
+ # 验证API Key
17
+ key = request.args.get('key')
18
+ if key != API_KEY:
19
+ return {"error": "Unauthorized"}, 401
20
+
21
+ # 从环境变量获取URL列表
22
+ if not SUBSCRIBE_URLS:
23
+ return {"error": "SUBSCRIBE_URLS not configured"}, 500
24
+
25
+ urls = SUBSCRIBE_URLS.split('\n')
26
+ cleaned_urls = [url.strip() for url in urls]
27
+ new_url = '|'.join(cleaned_urls)
28
+ encoded_url = urlencode({
29
+ 'target': 'clash',
30
+ 'url': new_url
31
+ }) # Correct way to encode the URL
32
+
33
+ target_url = f"http://127.0.0.1:25500/sub?{encoded_url}"
34
+
35
+ try:
36
+ resp = requests.get(target_url)
37
+ resp.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
38
+ data = resp.text
39
+ return Response(data, mimetype='text/yaml')
40
+ except requests.exceptions.RequestException as e:
41
+ return {"error": str(e)}, 500 # Handle request errors and return an error response
42
+
43
+
44
  @app.get("/")
45
  def read_root():
46
+ return {"hello": 'world'}
47
+
 
 
 
48
 
49
  asgi_app = WsgiToAsgi(app)