-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller2.py
More file actions
67 lines (53 loc) · 1.53 KB
/
controller2.py
File metadata and controls
67 lines (53 loc) · 1.53 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
60
61
62
63
64
65
66
67
from dal import UserDao
from datetime import datetime
import os
import subprocess
from flask import (
Flask,
request,
render_template,
render_template_string,
redirect,
session,
url_for,
send_file,
jsonify,
send_file
)
import shutil
import zipfile
from io import BytesIO
import shutil
# logging.basicConfig(filename="log.txt")
app = Flask(__name__)
@app.route('/browser')
def root():
search_query = request.args.get('search')
# Get the list of files and folders in the current directory
file_list = subprocess.check_output('ls', shell=True).decode('utf-8').split('\n')
# Filter the file list based on the search query
matching_files = []
if search_query:
matching_files = [file for file in file_list if search_query in file]
return render_template('browser.html', current_working_directory=os.getcwd(), file_list=file_list, matching_files=matching_files, search_query=search_query,os=os)
@app.route('/select')
def select():
file_path = request.args.get('file')
os.chdir(os.path.join(os.getcwd(), file_path))
return redirect("/")
# handle 'cd' command
@app.route('/cd')
def cd():
# run 'level up' command
os.chdir(request.args.get('path'))
# redirect to file manager
return redirect('/')
# view text files
@app.route('/view')
def view():
# get the file content
with open(request.args.get('file')) as f:
return f.read().replace('\n', '<br>')
# run the HTTP server
if __name__ == '__main__':
app.run(debug=True, threaded=True)