diff --git a/backend/main.py b/backend/main.py index e92c7a17..982e8550 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1319,6 +1319,45 @@ class AppServer: self.logger.error(f'检查会话检测数据存在失败: {e}') return jsonify({'success': False, 'error': str(e)}), 500 + @self.app.route('/api/detection//get_data', methods=['GET']) + def get_session_detection_data(session_id: str): + 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 + + result_data = [] + + # 处理检测数据 + if 'data' in session_data: + for item in session_data['data']: + item_copy = item.copy() + item_copy['type'] = 'data' + result_data.append(item_copy) + + # 处理视频数据 + if 'videos' in session_data: + for item in session_data['videos']: + item_copy = item.copy() + item_copy['type'] = 'video' + result_data.append(item_copy) + + # 按时间戳排序 + result_data.sort(key=lambda x: x.get('timestamp', ''), reverse=False) + + return jsonify({ + 'success': True, + 'session_id': session_id, + 'data': result_data + }) + except Exception as e: + self.logger.error(f'获取会话检测数据失败: {e}') + return jsonify({'success': False, 'error': str(e)}), 500 + @self.app.route('/api/detection//stop', methods=['POST']) def stop_detection(session_id): """停止检测"""