feat:导出功能重构

This commit is contained in:
liailing1026
2026-03-11 17:46:42 +08:00
parent 14b79bc282
commit 26c42697e8
20 changed files with 4070 additions and 126 deletions

View File

@@ -21,6 +21,7 @@ import yaml
import argparse
import uuid
import copy
import base64
from typing import List, Dict, Optional
# 数据库模块导入
@@ -2816,7 +2817,7 @@ EXPORT_TYPE_CONFIG = {
"markdown": {"ext": ".md", "mime": "text/markdown"},
"excel": {"ext": ".xlsx", "mime": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
"ppt": {"ext": ".pptx", "mime": "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
"mindmap": {"ext": ".md", "mime": "text/markdown"}, # 思维导图先用 markdown
"mindmap": {"ext": ".md", "mime": "text/markdown"}, # 思维导图导出为 Markdown 格式
"infographic": {"ext": ".html", "mime": "text/html"}, # 信息图先用 html
}
@@ -2889,13 +2890,19 @@ def handle_export(data):
return
# 准备导出数据
from datetime import datetime
current_date = datetime.now().strftime('%Y年%m月%d')
export_data = {
'task_name': task.query or '未命名任务',
'task_content': task.query or '', # 使用 query 作为任务描述
'task_content': task.query or '',
'task_outline': task.task_outline,
'result': task.result,
'agents_info': task.agents_info,
'assigned_agents': task.assigned_agents,
'rehearsal_log': task.rehearsal_log,
'agent_scores': task.agent_scores,
'user_id': user_id,
'date': current_date,
}
# 生成文件名
@@ -3066,6 +3073,35 @@ def preview_export(record_id: int):
with open(record.file_path, 'r', encoding='utf-8') as f:
content = f.read()
return jsonify({'content': content, 'type': 'markdown'})
elif record.export_type == 'mindmap':
# Markdown 格式的思维导图
with open(record.file_path, 'r', encoding='utf-8') as f:
content = f.read()
return jsonify({'content': content, 'type': 'mindmap'})
elif record.export_type in ['doc', 'docx']:
# Word 文件,直接返回文件流(使用 Flask 的 send_file
return send_file(
record.file_path,
mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
as_attachment=False,
download_name=record.file_name
)
elif record.export_type in ['excel', 'xlsx', 'xls']:
# Excel 文件,直接返回文件流
return send_file(
record.file_path,
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
as_attachment=False,
download_name=record.file_name
)
elif record.export_type in ['ppt', 'pptx']:
# PPT 文件,直接返回文件流
return send_file(
record.file_path,
mimetype='application/vnd.openxmlformats-officedocument.presentationml.presentation',
as_attachment=False,
download_name=record.file_name
)
else:
# 其他类型返回文件路径,前端自行处理
return jsonify({
@@ -3101,6 +3137,26 @@ def share_export(record_id: int):
return jsonify({'error': str(e)}), 500
@app.route('/api/export/<int:record_id>/share/info', methods=['GET'])
def get_share_info(record_id: int):
"""获取分享文件信息(无需登录验证)"""
try:
with get_db_context() as db:
record = ExportRecordCRUD.get_by_id(db, record_id)
if not record:
return jsonify({'error': '文件不存在或已失效'}), 404
return jsonify({
'file_name': record.file_name,
'export_type': record.export_type,
'created_at': record.created_at.isoformat() if record.created_at else None,
'file_size': record.file_size or 0,
})
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/api/export/<int:record_id>', methods=['DELETE'])
def delete_export(record_id: int):
"""删除导出记录"""