-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
32 lines (26 loc) · 859 Bytes
/
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
from flask import Flask, send_file, request
import os
app = Flask(__name__)
a = []
@app.route('/')
def list_files_recursive(path='/home/ubuntu/'):
for entry in os.listdir(path):
full_path = os.path.join(path, entry)
if os.path.isdir(full_path):
a.append({"filetype":"dir","path":full_path})
list_files_recursive(full_path)
else:
a.append({"filetype":"file","path":full_path})
return a
@app.route('/getfilecontent')
def returnContentofFile():
data = request.get_json()
filepath = data["path"]
if(os.path.exists(filepath)):
if os.path.isdir(filepath):
return {"error":"filetype is directory"},404
else:
return send_file(filepath)
else:
return {"error":"Invalid file Path"},404
app.run('0.0.0.0',4000,debug=True)