增加了删除报告的方法。
This commit is contained in:
parent
e8673b7115
commit
d5468ccc5b
@ -1490,6 +1490,48 @@ class AppServer:
|
||||
self.logger.error(f'上传报告失败: {e}')
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
@self.app.route('/api/reports/<session_id>/delete', methods=['POST'])
|
||||
def delete_report_pdf(session_id):
|
||||
"""删除会话的PDF报告"""
|
||||
try:
|
||||
if not self.db_manager:
|
||||
return jsonify({'success': False, 'error': '数据库管理器未初始化'}), 500
|
||||
|
||||
# 获取会话信息
|
||||
session_data = self.db_manager.get_session_data(session_id)
|
||||
if not session_data:
|
||||
return jsonify({'success': False, 'error': '检测会话不存在'}), 404
|
||||
|
||||
report_path = session_data.get('detection_report')
|
||||
if not report_path:
|
||||
return jsonify({'success': True, 'message': '报告不存在'}), 200
|
||||
|
||||
# 获取文件存储根目录
|
||||
base_dir_cfg = self.config_manager.get_config_value('FILEPATH', 'path', fallback=None) if self.config_manager else None
|
||||
if not base_dir_cfg:
|
||||
return jsonify({'success': False, 'error': '未配置文件存储路径'}), 500
|
||||
|
||||
base_dir = os.path.abspath(base_dir_cfg)
|
||||
full_path = os.path.join(base_dir, report_path)
|
||||
|
||||
# 删除文件
|
||||
if os.path.exists(full_path):
|
||||
try:
|
||||
os.remove(full_path)
|
||||
self.logger.info(f'已删除报告文件: {full_path}')
|
||||
except Exception as e:
|
||||
self.logger.error(f'删除文件失败: {e}')
|
||||
return jsonify({'success': False, 'error': f'删除文件失败: {str(e)}'}), 500
|
||||
|
||||
# 更新数据库
|
||||
self.db_manager.update_session_report_path(session_id, None)
|
||||
|
||||
return jsonify({'success': True, 'message': '报告已删除'})
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f'删除报告失败: {e}')
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
|
||||
@self.app.route('/api/detection/<session_id>/save-data', methods=['POST'])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user