[重构] 运动预过滤改为本地事件(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:
@@ -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 线程存活状态。
|
||||
|
||||
Reference in New Issue
Block a user