add param to reduce response sizes by excluding thumbnails in api response

This commit is contained in:
Blake Blackshear 2021-01-30 07:19:52 -06:00
parent 9a96df0319
commit b55bd1e027
2 changed files with 24 additions and 17 deletions

View File

@ -136,7 +136,7 @@ Version info
Events from the database. Accepts the following query string parameters: Events from the database. Accepts the following query string parameters:
| param | Type | Description | | param | Type | Description |
| -------------- | ---- | --------------------------------------------- | | -------------------- | ---- | --------------------------------------------- |
| `before` | int | Epoch time | | `before` | int | Epoch time |
| `after` | int | Epoch time | | `after` | int | Epoch time |
| `camera` | str | Camera name | | `camera` | str | Camera name |
@ -145,6 +145,7 @@ Events from the database. Accepts the following query string parameters:
| `limit` | int | Limit the number of events returned | | `limit` | int | Limit the number of events returned |
| `has_snapshot` | int | Filter to events that have snapshots (0 or 1) | | `has_snapshot` | int | Filter to events that have snapshots (0 or 1) |
| `has_clip` | int | Filter to events that have clips (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` ### `/api/events/summary`
@ -159,12 +160,13 @@ 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. 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/<id>/snapshot.jpg` ### `/api/events/<id>/snapshot.jpg`
Returns the snapshot image for the event id. Works while the event is in progress and after completion. 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: 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 | | param | Type | Description |
|----|-----|--| | ----------- | ---- | ------------------------------------------------- |
| `h` | int | Height in pixels | | `h` | int | Height in pixels |
| `bbox` | int | Show bounding boxes for detected objects (0 or 1) | | `bbox` | int | Show bounding boxes for detected objects (0 or 1) |
| `timestamp` | int | Print the timestamp in the upper left (0 or 1) | | `timestamp` | int | Print the timestamp in the upper left (0 or 1) |

View File

@ -164,8 +164,10 @@ def events():
before = request.args.get('before', type=int) before = request.args.get('before', type=int)
has_clip = request.args.get('has_clip', type=int) has_clip = request.args.get('has_clip', type=int)
has_snapshot = request.args.get('has_snapshot', type=int) has_snapshot = request.args.get('has_snapshot', type=int)
include_thumbnails = request.args.get('include_thumbnails', default=1, type=int)
clauses = [] clauses = []
excluded_fields = []
if camera: if camera:
clauses.append((Event.camera == camera)) clauses.append((Event.camera == camera))
@ -188,6 +190,9 @@ def events():
if not has_snapshot is None: if not has_snapshot is None:
clauses.append((Event.has_snapshot == has_snapshot)) clauses.append((Event.has_snapshot == has_snapshot))
if not include_thumbnails:
excluded_fields.append(Event.thumbnail)
if len(clauses) == 0: if len(clauses) == 0:
clauses.append((1 == 1)) clauses.append((1 == 1))
@ -196,7 +201,7 @@ def events():
.order_by(Event.start_time.desc()) .order_by(Event.start_time.desc())
.limit(limit)) .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') @bp.route('/config')
def config(): def config():