Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
from flask import Flask, render_template, request, redirect, url_for
|
2 |
from flask_socketio import SocketIO, emit
|
3 |
from flask_cors import CORS
|
4 |
-
from
|
5 |
import pty
|
6 |
import os
|
7 |
import subprocess
|
@@ -12,9 +12,13 @@ CORS(app) # 启用 CORS
|
|
12 |
app.config['SECRET_KEY'] = 'your_secret_key'
|
13 |
|
14 |
# 配置文件上传
|
|
|
|
|
|
|
|
|
15 |
app.config['UPLOADED_FILES_DEST'] = 'uploads' # 上传文件的保存目录
|
16 |
-
|
17 |
-
|
18 |
|
19 |
socketio = SocketIO(app)
|
20 |
|
@@ -33,13 +37,6 @@ def run_shell():
|
|
33 |
def index():
|
34 |
return render_template('index.html')
|
35 |
|
36 |
-
@app.route('/upload', methods=['POST'])
|
37 |
-
def upload_file():
|
38 |
-
if 'file' in request.files:
|
39 |
-
filename = files.save(request.files['file'])
|
40 |
-
return redirect(url_for('index'))
|
41 |
-
return 'No file uploaded', 400
|
42 |
-
|
43 |
@app.route('/files', defaults={'path': ''})
|
44 |
@app.route('/files/<path:path>')
|
45 |
def list_files(path):
|
@@ -51,10 +48,6 @@ def list_files(path):
|
|
51 |
files_and_dirs = [f for f in files_and_dirs if not f.startswith('.')] # 排除隐藏文件
|
52 |
return render_template('files.html', files=files_and_dirs, current_path=path)
|
53 |
|
54 |
-
@app.route('/files/<path:path>/<filename>')
|
55 |
-
def download_file(path, filename):
|
56 |
-
return send_from_directory(os.path.join(app.config['UPLOADED_FILES_DEST'], path), filename)
|
57 |
-
|
58 |
@socketio.on('input')
|
59 |
def handle_input(input_data):
|
60 |
os.write(master_fd, (input_data + '\n').encode('utf-8'))
|
@@ -65,4 +58,4 @@ if __name__ == '__main__':
|
|
65 |
shell_thread = threading.Thread(target=run_shell)
|
66 |
shell_thread.daemon = True
|
67 |
shell_thread.start()
|
68 |
-
socketio.run(app, host='0.0.0.0', port=7860, allow_unsafe_werkzeug=True)
|
|
|
1 |
+
from flask import Flask, render_template, request, redirect, url_for
|
2 |
from flask_socketio import SocketIO, emit
|
3 |
from flask_cors import CORS
|
4 |
+
from flask_dropzone import Dropzone
|
5 |
import pty
|
6 |
import os
|
7 |
import subprocess
|
|
|
12 |
app.config['SECRET_KEY'] = 'your_secret_key'
|
13 |
|
14 |
# 配置文件上传
|
15 |
+
app.config['DROPZONE_UPLOAD_MULTIPLE'] = False
|
16 |
+
app.config['DROPZONE_ALLOWED_FILE_TYPE'] = 'all'
|
17 |
+
app.config['DROPZONE_MAX_FILE_SIZE'] = 3 # 最大文件大小为3MB
|
18 |
+
app.config['DROPZONE_REDIRECT_VIEW'] = 'list_files'
|
19 |
app.config['UPLOADED_FILES_DEST'] = 'uploads' # 上传文件的保存目录
|
20 |
+
|
21 |
+
dropzone = Dropzone(app)
|
22 |
|
23 |
socketio = SocketIO(app)
|
24 |
|
|
|
37 |
def index():
|
38 |
return render_template('index.html')
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@app.route('/files', defaults={'path': ''})
|
41 |
@app.route('/files/<path:path>')
|
42 |
def list_files(path):
|
|
|
48 |
files_and_dirs = [f for f in files_and_dirs if not f.startswith('.')] # 排除隐藏文件
|
49 |
return render_template('files.html', files=files_and_dirs, current_path=path)
|
50 |
|
|
|
|
|
|
|
|
|
51 |
@socketio.on('input')
|
52 |
def handle_input(input_data):
|
53 |
os.write(master_fd, (input_data + '\n').encode('utf-8'))
|
|
|
58 |
shell_thread = threading.Thread(target=run_shell)
|
59 |
shell_thread.daemon = True
|
60 |
shell_thread.start()
|
61 |
+
socketio.run(app, host='0.0.0.0', port=7860, allow_unsafe_werkzeug=True)
|