From b55bd1e027968767913d006fa9dd91230d7387d6 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sat, 30 Jan 2021 07:19:52 -0600 Subject: [PATCH] add param to reduce response sizes by excluding thumbnails in api response --- docs/docs/usage/api.md | 34 ++++++++++++++++++---------------- frigate/http.py | 7 ++++++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/docs/usage/api.md b/docs/docs/usage/api.md index 73aea23a4..af48e1581 100644 --- a/docs/docs/usage/api.md +++ b/docs/docs/usage/api.md @@ -135,16 +135,17 @@ Version info Events from the database. Accepts the following query string parameters: -| param | Type | Description | -| -------------- | ---- | --------------------------------------------- | -| `before` | int | Epoch time | -| `after` | int | Epoch time | -| `camera` | str | Camera name | -| `label` | str | Label name | -| `zone` | str | Zone name | -| `limit` | int | Limit the number of events returned | -| `has_snapshot` | int | Filter to events that have snapshots (0 or 1) | -| `has_clip` | int | Filter to events that have clips (0 or 1) | +| param | Type | Description | +| -------------------- | ---- | --------------------------------------------- | +| `before` | int | Epoch time | +| `after` | int | Epoch time | +| `camera` | str | Camera name | +| `label` | str | Label name | +| `zone` | str | Zone name | +| `limit` | int | Limit the number of events returned | +| `has_snapshot` | int | Filter to events that have snapshots (0 or 1) | +| `has_clip` | int | Filter to events that have clips (0 or 1) | +| `include_thumbnails` | int | Include thumbnails in the response (0 or 1) | ### `/api/events/summary` @@ -159,16 +160,17 @@ Returns data for a single event. Returns a thumbnail for the event id optimized for notifications. Works while the event is in progress and after completion. Passing `?format=android` will convert the thumbnail to 2:1 aspect ratio. ### `/api/events//snapshot.jpg` + Returns the snapshot image for the event id. Works while the event is in progress and after completion. Accepts the following query string parameters, but they are only applied when an event is in progress. After the event is completed, the saved snapshot is returned from disk without modification: -|param|Type|Description| -|----|-----|--| -|`h`|int|Height in pixels| -|`bbox`|int|Show bounding boxes for detected objects (0 or 1)| -|`timestamp`|int|Print the timestamp in the upper left (0 or 1)| -|`crop`|int|Crop the snapshot to the (0 or 1)| +| param | Type | Description | +| ----------- | ---- | ------------------------------------------------- | +| `h` | int | Height in pixels | +| `bbox` | int | Show bounding boxes for detected objects (0 or 1) | +| `timestamp` | int | Print the timestamp in the upper left (0 or 1) | +| `crop` | int | Crop the snapshot to the (0 or 1) | ### `/clips/-.mp4` diff --git a/frigate/http.py b/frigate/http.py index 110778ca1..f89791d75 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -164,8 +164,10 @@ def events(): before = request.args.get('before', type=int) has_clip = request.args.get('has_clip', type=int) has_snapshot = request.args.get('has_snapshot', type=int) + include_thumbnails = request.args.get('include_thumbnails', default=1, type=int) clauses = [] + excluded_fields = [] if camera: clauses.append((Event.camera == camera)) @@ -188,6 +190,9 @@ def events(): if not has_snapshot is None: clauses.append((Event.has_snapshot == has_snapshot)) + if not include_thumbnails: + excluded_fields.append(Event.thumbnail) + if len(clauses) == 0: clauses.append((1 == 1)) @@ -196,7 +201,7 @@ def events(): .order_by(Event.start_time.desc()) .limit(limit)) - return jsonify([model_to_dict(e) for e in events]) + return jsonify([model_to_dict(e, exclude=excluded_fields) for e in events]) @bp.route('/config') def config():