diff --git a/frigate/api/defs/events_body.py b/frigate/api/defs/events_body.py index 6a33eda30..8bdbc7dda 100644 --- a/frigate/api/defs/events_body.py +++ b/frigate/api/defs/events_body.py @@ -5,8 +5,12 @@ from pydantic import BaseModel, Field class EventsSubLabelBody(BaseModel): - subLabel: str - subLabelScore: Optional[float] = None + subLabel: str = Field( + title="Sub label", max_length=100 + ) + subLabelScore: Optional[float] = Field( + title="Score for sub label", default=None, gt=0.0, le=1.0 + ) class EventsDescriptionBody(BaseModel): diff --git a/frigate/api/event.py b/frigate/api/event.py index a614edc7e..10953741c 100644 --- a/frigate/api/event.py +++ b/frigate/api/event.py @@ -10,7 +10,7 @@ from urllib.parse import unquote import cv2 import numpy as np -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, Body from fastapi.params import Depends from fastapi.responses import JSONResponse from peewee import JOIN, DoesNotExist, fn, operator @@ -841,7 +841,7 @@ def delete_retain(event_id: str): def set_sub_label( request: Request, event_id: str, - body: EventsSubLabelBody = None, + body: EventsSubLabelBody, ): try: event: Event = Event.get(Event.id == event_id) @@ -854,32 +854,6 @@ def set_sub_label( new_sub_label = body.subLabel new_score = body.subLabelScore - # TODO: Rui Move this validation to the EventsSubLabelBody. Str between 0 and 100 chars - if new_sub_label and len(new_sub_label) > 100: - return JSONResponse( - content=( - { - "success": False, - "message": new_sub_label - + " exceeds the 100 character limit for sub_label", - } - ), - status_code=400, - ) - - # TODO: Rui Move this validation to the EventsSubLabelBody. Str between 0 and 100 chars - if new_score is not None and (new_score > 1.0 or new_score < 0): - return JSONResponse( - content=( - { - "success": False, - "message": new_score - + " does not fit within the expected bounds 0 <= score <= 1.0", - } - ), - status_code=400, - ) - if not event.end_time: # update tracked object tracked_obj: TrackedObject = ( @@ -919,7 +893,7 @@ def set_sub_label( def set_description( request: Request, event_id: str, - body: EventsDescriptionBody = None, + body: EventsDescriptionBody, ): try: event: Event = Event.get(Event.id == event_id) diff --git a/frigate/app.py b/frigate/app.py index 3b22f19ef..d0947359e 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -735,13 +735,6 @@ class FrigateApp: self.start_watchdog() self.init_auth() - # TODO: Rui. What to do in this case? Maybe https://github.com/encode/uvicorn/issues/1579#issuecomment-1419635974 - # Flask only listens for SIGINT, so we need to catch SIGTERM and send SIGINT - def receiveSignal(signalNumber: int, frame: Optional[FrameType]) -> None: - os.kill(os.getpid(), signal.SIGINT) - - signal.signal(signal.SIGTERM, receiveSignal) - try: uvicorn.run( self.fastapi_app,