新增消息类型:语音,视频
This commit is contained in:
@@ -23,8 +23,12 @@ message_thread_pool = ThreadPoolExecutor(max_workers=10, thread_name_prefix="mes
|
||||
shared_loop = None
|
||||
loop_lock = threading.Lock()
|
||||
|
||||
# 允许的图片文件扩展名
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
||||
# 允许的文件扩展名
|
||||
ALLOWED_EXTENSIONS = {
|
||||
'image': {'png', 'jpg', 'jpeg', 'gif'},
|
||||
'voice': {'mp3', 'wav'},
|
||||
'video': {'mp4'}
|
||||
}
|
||||
|
||||
|
||||
def get_or_create_loop():
|
||||
@@ -69,8 +73,9 @@ def send_message_in_thread(func, *args, **kwargs):
|
||||
message_thread_pool.submit(run)
|
||||
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||
def allowed_file(filename, file_type='image'):
|
||||
"""检查文件类型是否允许上传"""
|
||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS.get(file_type, set())
|
||||
|
||||
|
||||
# 消息推送管理页面
|
||||
@@ -503,7 +508,7 @@ def api_statistics():
|
||||
|
||||
@message_push_bp.route('/api/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
"""处理图片上传"""
|
||||
"""处理文件上传"""
|
||||
if 'file' not in request.files:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
@@ -517,7 +522,14 @@ def upload_file():
|
||||
'message': '没有选择文件'
|
||||
})
|
||||
|
||||
if file and allowed_file(file.filename):
|
||||
# 根据文件类型检查
|
||||
file_type = 'image' # 默认类型
|
||||
if file.content_type.startswith('audio/'):
|
||||
file_type = 'voice'
|
||||
elif file.content_type.startswith('video/'):
|
||||
file_type = 'video'
|
||||
|
||||
if file and allowed_file(file.filename, file_type):
|
||||
# 生成安全的文件名
|
||||
filename = secure_filename(file.filename)
|
||||
# 生成唯一文件名
|
||||
|
||||
Reference in New Issue
Block a user