Use custom body for the export recordings endpoint

This commit is contained in:
Rui Alves 2024-11-10 20:44:44 +00:00
parent a68c7f4ef8
commit 0027e3fd96
4 changed files with 20 additions and 14 deletions

View File

View File

View File

@ -0,0 +1,14 @@
from typing import Optional
from pydantic import BaseModel, Field
from frigate.record.export import PlaybackFactorEnum
class ExportRecordingsBody(BaseModel):
playback: PlaybackFactorEnum = Field(
default=PlaybackFactorEnum.realtime, title="Playback factor"
)
source: str = "recordings"
name: str = Field(title="Friendly name", default=None, min_length=1, max_length=256)
image_path: Optional[str] = None

View File

@ -4,13 +4,13 @@ import logging
import random
import string
from pathlib import Path
from typing import Optional
import psutil
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse
from peewee import DoesNotExist
from frigate.api.defs.request.export_recordinds_body import ExportRecordingsBody
from frigate.api.defs.tags import Tags
from frigate.const import EXPORT_DIR
from frigate.models import Export, Previews, Recordings
@ -37,7 +37,7 @@ def export_recording(
camera_name: str,
start_time: float,
end_time: float,
body: dict = None,
body: dict = ExportRecordingsBody,
):
if not camera_name or not request.app.frigate_config.cameras.get(camera_name):
return JSONResponse(
@ -47,18 +47,10 @@ def export_recording(
status_code=404,
)
json: dict[str, any] = body or {}
playback_factor = json.get("playback", "realtime")
playback_source = json.get("source", "recordings")
friendly_name: Optional[str] = json.get("name")
if len(friendly_name or "") > 256:
return JSONResponse(
content=({"success": False, "message": "File name is too long."}),
status_code=401,
)
existing_image = json.get("image_path")
playback_factor = body.playback
playback_source = body.source
friendly_name = body.name
existing_image = body.image_path
if playback_source == "recordings":
recordings_count = (