-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (53 loc) · 1.82 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
from flask import Flask, request, redirect, jsonify
from werkzeug.utils import secure_filename
import os
import static
import dynamic
app = Flask(__name__)
@app.route('/api/test', methods=['GET'])
def test():
return jsonify({'message': 'Hello World!'})
@app.route('/api/static', methods=['POST'])
def static_route():
if 'file' not in request.files:
resp = jsonify({'result' : 'No file part in the request'})
resp.status_code = 400
return resp
file = request.files['file']
if file.filename == '':
resp = jsonify({'result' : 'No file selected for uploading'})
resp.status_code = 400
return resp
if file:
filename = secure_filename(file.filename)
file.save(filename)
response, code = static.static_analysis(file.filename)
resp = jsonify(response)
resp.status_code = code
return resp
@app.route('/api/dynamic', methods=['POST'])
def dynamic_route():
if 'file' not in request.files:
resp = jsonify({'result' : 'No file part in the request'})
resp.status_code = 400
return resp
file = request.files['file']
if file.filename == '':
resp = jsonify({'result' : 'No file selected for uploading'})
resp.status_code = 400
return resp
if file:
filename = secure_filename(file.filename)
file.save(filename)
response, code = dynamic.dynamic(file.filename, is_python_script=True, is_full_strace=True)
resp = jsonify(response)
resp.status_code = code
return resp
@app.route('/api/upload', methods=['POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
if __name__ == "__main__":
app.run(port=8000, debug=True)