from flask import Flask, request, jsonify import os # 配置上传目录和文件限制 UPLOAD_FOLDER = '/mnt/sese' ALLOWED_EXTENSIONS = { 'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'md', 'doc', 'docx','mp4','mov','wmv','avi','m4v','mpg', 'xlsx', 'xls', 'rar', 'zip', 'java', 'sql', 'py', 'css','conf','sql','properties','yaml','html','htm','jsp','js','json','yml' } MAX_FILE_SIZE = 88 * 1024 * 1024 # 88MB app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['MAX_CONTENT_LENGTH'] = MAX_FILE_SIZE def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': if 'file' not in request.files: return jsonify({'status': 'error', 'message': 'No file part'}), 400 file = request.files['file'] if file.filename == '': return jsonify({'status': 'error', 'message': 'No selected file'}), 400 if file and allowed_file(file.filename): filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) file.save(filepath) return jsonify({'status': 'success', 'message': 'File uploaded successfully'}), 200 return jsonify({'status': 'error', 'message': 'File type not allowed'}), 400 # GET 请求返回 HTML 页面 files = os.listdir(app.config['UPLOAD_FOLDER']) files_list_html = ''.join( f'