-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
151 lines (100 loc) · 3.64 KB
/
app.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import dotenv
import json
from os import getenv, path
from flask import Flask, jsonify, request, send_file, send_from_directory, safe_join, abort
from Directories import Directories
from pathlib import Path
from middleware import *
from validation import *
from flask_cors import CORS, cross_origin
from flask_jwt_extended import (
JWTManager, jwt_required, create_access_token,
get_jwt_identity, decode_token
)
app = Flask(__name__)
#cors = CORS(app, resources={r"*": {"origins": "*", "supports_credentials": True}})
CORS(app)
app.config['JWT_SECRET_KEY'] = getenv('SECRET_KEY')
jwt = JWTManager(app)
@app.route('/users/', methods = ['GET', 'POST', 'DELETE'])
def users():
return jsonify({})
@app.route('/user/', methods = ['GET', 'POST', 'DELETE'])
def user():
return jsonify({})
@app.route('/host/config/', methods = ['GET', 'POST', 'DELETE'])
def changeConfig():
return jsonify({})
@app.route('/reset/', methods = ['GET', 'POST', 'DELETE'])
def resetServer():
return jsonify({})
@app.route('/host/', methods = ['GET', 'POST', 'DELETE'])
def host():
return jsonify({})
@app.route('/alive/', methods = ['GET', 'POST', 'DELETE'])
def is_alive():
return jsonify({"is_running" : True, "status" : True})
@app.route('/init/', methods = ['GET', 'POST', 'DELETE'])
def alive():
return jsonify({})
@app.route('/dirEx/')
def getDirs():
req = request.json
if isValidPath(req):
return jsonify(Directories.getDirData(req.get('path')))
else:
return jsonify({"msg": "Invalid path"})
@app.route('/file/upload/', methods = ['GET', 'POST'])
@jwt_required
def uploadFile():
files = request.files
req = request.args
token = req.get("token")
tokenData = decode_token(token)
tokenIdentity = tokenData.get("identity")
if tokenIdentity.get("username") != get_jwt_identity():
return allowCors(jsonify({"msg" : "Corrupted user"}), 400)
#Pending
pass
if isValidPath(req):
files['file'].save(path.join(req.get('path'), files['file'].filename))
return allowCors(jsonify({"msg":"Success"}))
else:
return allowCors(jsonify({"msg": "Invalid Path"}), 400)
@app.route("/testRoute/", methods = ["GET", "POST"])
def heelo():
req = request.args
mainToken = decode_token(req.get("m_token"))
token = req.get("token")
tokenData = decode_token(token)
tokenIdentity = tokenData.get("identity")
if tokenIdentity.get("username") != mainToken.get("identity"):
return allowCors(jsonify({"msg" : "Corrupted user"}), 400)
#Pending
pass
if isValidPath({"path": safe_join(req.get('path'), req.get('file_name'))}, False):
return send_from_directory(Path(req.get('path')), filename = req.get('file_name'), as_attachment=True)
else:
return allowCors(jsonify({"msg" : "Invalid Path"}), 400)
@app.route("/dir/", methods = ['GET'])
@jwt_required
def getFolder():
req = request.args
token = req.get("token")
tokenData = decode_token(token)
tokenIdentity = tokenData.get("identity")
if tokenIdentity.get("username") != get_jwt_identity():
return allowCors(jsonify({"msg" : "Corrupted user"}), 400)
#Pending
pass
path = req.get('path')
if path:
path = path.strip()
if path == None or path == '':
return allowCors(jsonify({"path":None, "data":[]}))
if not Path(path).exists():
return allowCors(jsonify({"path":None, "data":[]}))
data = Directories.getDirData(req.get('path'))
return allowCors(jsonify(data))
if __name__ == '__main__':
app.run(debug=True)