猜歌名,加上撤回策略。
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import asyncio
|
||||
import threading
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from flask import Blueprint, render_template, jsonify, request, current_app, session
|
||||
from .auth import login_required
|
||||
from loguru import logger
|
||||
import os
|
||||
import json
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, render_template, jsonify, request, current_app, session
|
||||
from werkzeug.utils import secure_filename
|
||||
from .auth import login_required
|
||||
from loguru import logger
|
||||
|
||||
# 创建消息推送管理蓝图
|
||||
message_push_bp = Blueprint('message_push', __name__, url_prefix='/message_push')
|
||||
@@ -19,6 +20,9 @@ message_thread_pool = ThreadPoolExecutor(max_workers=10, thread_name_prefix="mes
|
||||
shared_loop = None
|
||||
loop_lock = threading.Lock()
|
||||
|
||||
# 允许的图片文件扩展名
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
||||
|
||||
|
||||
def get_or_create_loop():
|
||||
"""获取或创建共享的事件循环"""
|
||||
@@ -62,6 +66,10 @@ 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
|
||||
|
||||
|
||||
# 消息推送管理页面
|
||||
@message_push_bp.route('/')
|
||||
@login_required
|
||||
@@ -363,3 +371,47 @@ def api_statistics():
|
||||
except Exception as e:
|
||||
logger.error(f"获取任务统计信息失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@message_push_bp.route('/api/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
"""处理图片上传"""
|
||||
if 'file' not in request.files:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': '没有文件'
|
||||
})
|
||||
|
||||
file = request.files['file']
|
||||
if file.filename == '':
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': '没有选择文件'
|
||||
})
|
||||
|
||||
if file and allowed_file(file.filename):
|
||||
# 生成安全的文件名
|
||||
filename = secure_filename(file.filename)
|
||||
# 生成唯一文件名
|
||||
unique_filename = f"{uuid.uuid4().hex}_{filename}"
|
||||
|
||||
# 确保上传目录存在
|
||||
upload_folder = os.path.join(current_app.root_path, 'static', 'uploads')
|
||||
os.makedirs(upload_folder, exist_ok=True)
|
||||
|
||||
# 保存文件
|
||||
file_path = os.path.join(upload_folder, unique_filename)
|
||||
file.save(file_path)
|
||||
|
||||
# 返回文件的绝对路径
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'data': {
|
||||
'url': file_path # 返回绝对路径
|
||||
}
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': '不支持的文件类型'
|
||||
})
|
||||
|
||||
@@ -553,9 +553,11 @@ new Vue({
|
||||
this.dialogTitle = '编辑任务';
|
||||
this.taskForm = { ...task };
|
||||
if (task.content_image) {
|
||||
// 编辑时显示图片
|
||||
const fileName = task.content_image.split('/').pop();
|
||||
this.imageList = [{
|
||||
name: '已上传图片',
|
||||
url: task.content_image
|
||||
url: `/static/uploads/${fileName}` // 显示时使用相对路径
|
||||
}];
|
||||
}
|
||||
this.taskDialogVisible = true;
|
||||
@@ -685,10 +687,12 @@ new Vue({
|
||||
// 图片上传相关
|
||||
handleImageSuccess(response, file) {
|
||||
if (response.success) {
|
||||
this.taskForm.content_image = response.data.url;
|
||||
this.taskForm.content_image = response.data.url; // 存储绝对路径
|
||||
// 显示时使用文件名
|
||||
const fileName = file.name;
|
||||
this.imageList = [{
|
||||
name: file.name,
|
||||
url: response.data.url
|
||||
name: fileName,
|
||||
url: `/static/uploads/${response.data.url.split('/').pop()}` // 显示时使用相对路径
|
||||
}];
|
||||
} else {
|
||||
this.$message.error('上传失败');
|
||||
@@ -711,7 +715,9 @@ new Vue({
|
||||
},
|
||||
|
||||
handleImagePreview(file) {
|
||||
this.previewUrl = file.url;
|
||||
// 预览时使用相对路径
|
||||
const fileName = file.url.split('/').pop();
|
||||
this.previewUrl = `/static/uploads/${fileName}`;
|
||||
this.previewVisible = true;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user