fix(api): 事件截图接口兜底 - ev_{id}.jpg 缺失时返回所属视频首帧缩略图(thumbs/{video_id}.jpg),避免旧事件/未生成截图导致前端头像空白
This commit is contained in:
@@ -141,11 +141,23 @@ def event_thumb(event_id):
|
|||||||
|
|
||||||
由 video_processor 处理成功后按事件时间戳定位视频帧生成:
|
由 video_processor 处理成功后按事件时间戳定位视频帧生成:
|
||||||
/opt/fam-edge/thumbs/ev_{event_id}.jpg
|
/opt/fam-edge/thumbs/ev_{event_id}.jpg
|
||||||
|
若该事件截图缺失(如旧事件/未生成),兜底返回所属视频的首帧缩略图
|
||||||
|
thumbs/{video_id}.jpg,避免前端图片空白。
|
||||||
"""
|
"""
|
||||||
if not _check_token():
|
if not _check_token():
|
||||||
return jsonify({"error": "unauthorized"}), 401
|
return jsonify({"error": "unauthorized"}), 401
|
||||||
path = f"/opt/fam-edge/thumbs/ev_{event_id}.jpg"
|
path = f"/opt/fam-edge/thumbs/ev_{event_id}.jpg"
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
|
# 兜底:查事件所属视频,返回视频首帧缩略图
|
||||||
|
try:
|
||||||
|
row = state.get_db()._conn.execute(
|
||||||
|
"SELECT video_id FROM events WHERE id=?", (event_id,)).fetchone()
|
||||||
|
if row and row['video_id']:
|
||||||
|
vpath = f"/opt/fam-edge/thumbs/{row['video_id']}.jpg"
|
||||||
|
if os.path.isfile(vpath):
|
||||||
|
return send_file(vpath, mimetype='image/jpeg')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return jsonify({"error": "thumb_not_found"}), 404
|
return jsonify({"error": "thumb_not_found"}), 404
|
||||||
return send_file(path, mimetype='image/jpeg')
|
return send_file(path, mimetype='image/jpeg')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user