mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Add cosntraints to api provided values
This commit is contained in:
parent
920f369473
commit
ecfc86e553
@ -5,8 +5,12 @@ from pydantic import BaseModel, Field
|
|||||||
|
|
||||||
|
|
||||||
class EventsSubLabelBody(BaseModel):
|
class EventsSubLabelBody(BaseModel):
|
||||||
subLabel: str
|
subLabel: str = Field(
|
||||||
subLabelScore: Optional[float] = None
|
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):
|
class EventsDescriptionBody(BaseModel):
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from urllib.parse import unquote
|
|||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request, Body
|
||||||
from fastapi.params import Depends
|
from fastapi.params import Depends
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from peewee import JOIN, DoesNotExist, fn, operator
|
from peewee import JOIN, DoesNotExist, fn, operator
|
||||||
@ -841,7 +841,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: EventsSubLabelBody = None,
|
body: EventsSubLabelBody,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
event: Event = Event.get(Event.id == event_id)
|
event: Event = Event.get(Event.id == event_id)
|
||||||
@ -854,32 +854,6 @@ def set_sub_label(
|
|||||||
new_sub_label = body.subLabel
|
new_sub_label = body.subLabel
|
||||||
new_score = body.subLabelScore
|
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:
|
if not event.end_time:
|
||||||
# update tracked object
|
# update tracked object
|
||||||
tracked_obj: TrackedObject = (
|
tracked_obj: TrackedObject = (
|
||||||
@ -919,7 +893,7 @@ def set_sub_label(
|
|||||||
def set_description(
|
def set_description(
|
||||||
request: Request,
|
request: Request,
|
||||||
event_id: str,
|
event_id: str,
|
||||||
body: EventsDescriptionBody = None,
|
body: EventsDescriptionBody,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
event: Event = Event.get(Event.id == event_id)
|
event: Event = Event.get(Event.id == event_id)
|
||||||
|
|||||||
@ -735,13 +735,6 @@ class FrigateApp:
|
|||||||
self.start_watchdog()
|
self.start_watchdog()
|
||||||
self.init_auth()
|
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:
|
try:
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
self.fastapi_app,
|
self.fastapi_app,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user