[重构] 运动预过滤改为本地事件(NAS推送) - 甲骨文不再反向访问NAS:新增 ss_motion_events 表/record_motion_events/has_motion_in_range_local,/api/ss/motion 接收端点,video_processor 改用本地运动事件预过滤,停用 dsm_motion_client 反向查询

This commit is contained in:
ericwyuan
2026-08-22 10:25:56 +08:00
parent 0d8e62607c
commit 38dea6ba2e
5 changed files with 136 additions and 22 deletions

View File

@@ -197,6 +197,36 @@ def oracle_avatar():
return Response(data, mimetype='image/jpeg')
@api_bp.route('/api/ss/motion', methods=['POST'])
def ss_motion():
"""接收 NAS 推送的运动侦测事件单向NAS -> Oracle
请求体: {"token": "...", "events": [
{"event_id": 25349, "camera_id": 2, "event_type": 10,
"start_time": 1787318023, "duration": 149, "thumbnail_url": "107471,12075"}
]}
start_time/duration 为 Unix epoch与 SS 同源,时区无关)。
落库 ss_motion_events按 event_id 幂等),供 video_processor 本地预过滤使用。
"""
if not _check_token():
return jsonify({"error": "unauthorized"}), 401
data = request.get_json(silent=True)
if not data or 'events' not in data:
return jsonify({"error": "缺少 events"}), 400
events = data.get('events') or []
if not isinstance(events, list):
return jsonify({"error": "events 必须是数组"}), 400
try:
stored = state.get_db().record_motion_events(events)
except Exception as e:
logger.error(f"ss_motion 落库异常: {e}")
return jsonify({"error": str(e)}), 500
if stored:
state.get_db().record_activity(
'motion', 'push', f"接收 NAS 运动事件 {stored}")
return jsonify({"status": "ok", "received": len(events), "stored": stored}), 200
@api_bp.route('/health', methods=['GET'])
def health():
"""健康检查DB 连通性 + producer/consumer 线程存活状态。