-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (39 loc) · 1.23 KB
/
app.py
File metadata and controls
51 lines (39 loc) · 1.23 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
from flask import Flask, request
from modules.data import save_data, add_data, clear_data
from modules.tokens import verify_token
app = Flask(__name__)
def check(r: dict) -> bool:
if ('token' not in r.keys()) or (not verify_token(r['token'])):
print('x> Connection refused: wrong token or no token')
return False
else:
print('-> Connection authorized')
return True
@app.route('/', methods=['GET'])
def index() -> str:
return 'Flask Server is running'
@app.route('/store_data', methods=['POST'])
def store_data() -> str:
new_data = request.json
if check(new_data):
del new_data['token'] # Remove the token before adding the data
return add_data(new_data)
else:
return 'Not authorized'
@app.route('/command', methods=['POST'])
def command() -> str:
r = request.json
if check(r):
if 'command' in r.keys():
if r['command'] == 'save':
return save_data()
elif r['command'] == 'clear':
return clear_data()
else:
return 'Command unknown'
else:
return 'No command'
else:
return 'Not authorized'
if __name__ == '__main__':
app.run()