mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-09 04:35:25 +03:00
Add snapshot-clean.png API endpoint
This commit is contained in:
parent
e4d0e222e3
commit
fad079fc49
@ -290,6 +290,14 @@ Returns a thumbnail for the event id optimized for notifications. Works while th
|
||||
|
||||
Returns the clip for the event id. Works after the event has ended.
|
||||
|
||||
### `GET /api/events/<id>/snapshot-clean.png`
|
||||
|
||||
Returns the clean snapshot image for the event id. Only works after an event has completed and if `snapshots` and `clean_copy` are enabled in the config.
|
||||
|
||||
| param | Type | Description |
|
||||
| ---------- | ---- | ------------------ |
|
||||
| `download` | bool | Download the image |
|
||||
|
||||
### `GET /api/events/<id>/snapshot.jpg`
|
||||
|
||||
Returns the snapshot image for the event id. Works while the event is in progress and after completion.
|
||||
@ -303,6 +311,7 @@ Accepts the following query string parameters, but they are only applied when an
|
||||
| `timestamp` | int | Print the timestamp in the upper left (0 or 1) |
|
||||
| `crop` | int | Crop the snapshot to the (0 or 1) |
|
||||
| `quality` | int | Jpeg encoding quality (0-100). Defaults to 70. |
|
||||
| `download` | bool | Download the image |
|
||||
|
||||
### `POST /api/events/<camera_name>/<label>/create`
|
||||
|
||||
|
||||
@ -935,6 +935,54 @@ def grid_snapshot(camera_name):
|
||||
)
|
||||
|
||||
|
||||
@MediaBp.route("/events/<id>/snapshot-clean.png")
|
||||
def event_snapshot_clean(id):
|
||||
download = request.args.get("download", type=bool)
|
||||
try:
|
||||
event = Event.get(Event.id == id)
|
||||
if event.end_time is None:
|
||||
return make_response(
|
||||
jsonify({"success": False, "message": "Event not complete"}), 404
|
||||
)
|
||||
if not event.has_snapshot:
|
||||
return make_response(
|
||||
jsonify({"success": False, "message": "Snapshot not available"}), 404
|
||||
)
|
||||
except DoesNotExist:
|
||||
return make_response(
|
||||
jsonify({"success": False, "message": "Event not found"}), 404
|
||||
)
|
||||
try:
|
||||
clean_snapshot_path = os.path.join(
|
||||
CLIPS_DIR, f"{event.camera}-{event.id}-clean.png"
|
||||
)
|
||||
if not os.path.exists(clean_snapshot_path):
|
||||
return make_response(
|
||||
jsonify({"success": False, "message": "Clean snapshot not available"}),
|
||||
404,
|
||||
)
|
||||
with open(
|
||||
os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}-clean.png"), "rb"
|
||||
) as image_file:
|
||||
png_bytes = image_file.read()
|
||||
except Exception:
|
||||
logger.error(f"Unable to load clean png for event: {event.id}")
|
||||
return make_response(
|
||||
jsonify(
|
||||
{"success": False, "message": "Unable to load clean png for event"}
|
||||
),
|
||||
400,
|
||||
)
|
||||
response = make_response(png_bytes)
|
||||
response.headers["Content-Type"] = "image/png"
|
||||
response.headers["Cache-Control"] = "private, max-age=31536000"
|
||||
if download:
|
||||
response.headers[
|
||||
"Content-Disposition"
|
||||
] = f"attachment; filename=snapshot-{id}-clean.png"
|
||||
return response
|
||||
|
||||
|
||||
@MediaBp.route("/events/<id>/snapshot.jpg")
|
||||
def event_snapshot(id):
|
||||
download = request.args.get("download", type=bool)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user