mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 15:45:27 +03:00
Use body for multiple events endpoints
This commit is contained in:
parent
1b601b8c35
commit
55d33cebb8
14
frigate/api/defs/events_body.py
Normal file
14
frigate/api/defs/events_body.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
class EventsSubLabelBody(BaseModel):
|
||||||
|
subLabel: str
|
||||||
|
subLabelScore: float
|
||||||
|
|
||||||
|
|
||||||
|
class EventsDescriptionBody(BaseModel):
|
||||||
|
description: Union[str, None] = Field(
|
||||||
|
title="The description of the event", min_length=1
|
||||||
|
)
|
||||||
@ -18,6 +18,7 @@ from peewee import JOIN, DoesNotExist, fn, operator
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
|
from frigate.api.defs.events_body import EventsDescriptionBody, EventsSubLabelBody
|
||||||
from frigate.api.defs.events_query_parameters import (
|
from frigate.api.defs.events_query_parameters import (
|
||||||
DEFAULT_TIME_RANGE,
|
DEFAULT_TIME_RANGE,
|
||||||
EventsQueryParams,
|
EventsQueryParams,
|
||||||
@ -585,7 +586,7 @@ def event(event_id: str):
|
|||||||
try:
|
try:
|
||||||
return model_to_dict(Event.get(Event.id == event_id))
|
return model_to_dict(Event.get(Event.id == event_id))
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
return "Event not found", 404
|
return JSONResponse(content="Event not found", status_code=404)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/events/{event_id}/retain")
|
@router.post("/events/{event_id}/retain")
|
||||||
@ -833,7 +834,7 @@ def delete_retain(event_id: str):
|
|||||||
def set_sub_label(
|
def set_sub_label(
|
||||||
request: Request,
|
request: Request,
|
||||||
event_id: str,
|
event_id: str,
|
||||||
body: dict = None,
|
body: EventsSubLabelBody = None,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
event: Event = Event.get(Event.id == event_id)
|
event: Event = Event.get(Event.id == event_id)
|
||||||
@ -843,9 +844,8 @@ def set_sub_label(
|
|||||||
status_code=404,
|
status_code=404,
|
||||||
)
|
)
|
||||||
|
|
||||||
json: dict[str, any] = body or {}
|
new_sub_label = body.subLabel
|
||||||
new_sub_label = json.get("subLabel")
|
new_score = body.subLabelScore
|
||||||
new_score = json.get("subLabelScore")
|
|
||||||
|
|
||||||
if new_sub_label is None:
|
if new_sub_label is None:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@ -921,7 +921,7 @@ def set_sub_label(
|
|||||||
def set_description(
|
def set_description(
|
||||||
request: Request,
|
request: Request,
|
||||||
event_id: str,
|
event_id: str,
|
||||||
body: dict = None,
|
body: EventsDescriptionBody = None,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
event: Event = Event.get(Event.id == event_id)
|
event: Event = Event.get(Event.id == event_id)
|
||||||
@ -931,8 +931,7 @@ def set_description(
|
|||||||
status_code=404,
|
status_code=404,
|
||||||
)
|
)
|
||||||
|
|
||||||
json: dict[str, any] = body or {}
|
new_description = body.description
|
||||||
new_description = json.get("description")
|
|
||||||
|
|
||||||
if new_description is None or len(new_description) == 0:
|
if new_description is None or len(new_description) == 0:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from typing import Optional
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
from frigate.api import app as main_app
|
from frigate.api import app as main_app
|
||||||
from frigate.api import export, media, notification, preview, review
|
from frigate.api import event, export, media, notification, preview, review
|
||||||
from frigate.embeddings import EmbeddingsContext
|
from frigate.embeddings import EmbeddingsContext
|
||||||
from frigate.events.external import ExternalEventProcessor
|
from frigate.events.external import ExternalEventProcessor
|
||||||
from frigate.plus import PlusApi
|
from frigate.plus import PlusApi
|
||||||
@ -37,6 +37,7 @@ def create_fastapi_app(
|
|||||||
app.include_router(notification.router)
|
app.include_router(notification.router)
|
||||||
app.include_router(review.router)
|
app.include_router(review.router)
|
||||||
app.include_router(export.router)
|
app.include_router(export.router)
|
||||||
|
app.include_router(event.router)
|
||||||
# App Properties
|
# App Properties
|
||||||
app.frigate_config = frigate_config
|
app.frigate_config = frigate_config
|
||||||
app.embeddings = embeddings
|
app.embeddings = embeddings
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user