-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (52 loc) · 1.76 KB
/
app.py
File metadata and controls
59 lines (52 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import flask
import random
password = os.getenv("password")
app = flask.Flask(__name__)
def return_random_key():
"返回随机 API Key"
with open("config/key", "r", encoding="utf-8") as f:
keys = f.readlines()
return random.choice(keys).strip()
def return_all_key():
"""返回所有 API Key"""
with open("config/key", "r", encoding="utf-8") as f:
keys = f.readlines()
keys = [ i.strip() for i in keys ]
return keys # Keys Not Kiss (^_^)
@app.route("/")
def index():
return flask.Response(status=404)
@app.route("/api/random", methods=["GET", "POST"])
def random_key():
if password is None:
"""无密码设置"""
return flask.Response(status=403)
elif flask.request.method == "POST" and flask.request.form.get("password") == password:
"""处理 POST 请求"""
return return_random_key()
elif flask.request.method == "GET" and flask.request.args.get("password") == password:
"""处理 GET 请求"""
return return_random_key()
else:
"""啥也不是"""
return flask.Response(status=403)
@app.route("/api/all", methods=["GET", "POST"])
def all_key():
if password is None:
"""无密码设置"""
return flask.Response(status=403)
elif flask.request.method == "POST" and flask.request.form.get("password") == password:
"""处理 POST 请求"""
return return_all_key()
elif flask.request.method == "GET" and flask.request.args.get("password") == password:
"""处理 GET 请求"""
return return_all_key()
else:
"""啥也不是"""
return flask.Response(status=403)
@app.route("/api/")
def no_content():
return flask.Response(status=404)
if __name__ == "__main__":
app.run()