Adding recording (#29)
Reviewed-on: #29 Co-authored-by: Andrew Kettel <andrew.kettel@gmail.com> Co-committed-by: Andrew Kettel <andrew.kettel@gmail.com>
This commit was merged in pull request #29.
This commit is contained in:
@@ -46,6 +46,7 @@ class CameraStatus(Base):
|
||||
|
||||
class CameraEvent(Base):
|
||||
__tablename__ = "camera_events"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
action: Mapped[str] = mapped_column(String(10), nullable=False) # 'start' | 'stop'
|
||||
ip_address: Mapped[str] = mapped_column(String(45), nullable=False)
|
||||
@@ -73,3 +74,44 @@ class CameraEvent(Base):
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
class CameraRecordingEvent(Base):
|
||||
"""Audit log for recording start/stop actions."""
|
||||
|
||||
__tablename__ = "camera_recording_events"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
action: Mapped[str] = mapped_column(
|
||||
String(20), nullable=False
|
||||
) # 'record_start' | 'record_stop'
|
||||
ip_address: Mapped[str] = mapped_column(String(45), nullable=False)
|
||||
file_path: Mapped[str] = mapped_column(String(512), nullable=False, default="")
|
||||
timestamp: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=lambda: datetime.now(UTC),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def log(action: str, ip_address: str, file_path: str = "") -> CameraRecordingEvent:
|
||||
event = CameraRecordingEvent(
|
||||
action=action,
|
||||
ip_address=ip_address,
|
||||
file_path=file_path,
|
||||
)
|
||||
db.session.add(event)
|
||||
db.session.commit()
|
||||
return event
|
||||
|
||||
@staticmethod
|
||||
def recent(limit: int = 50) -> list[CameraRecordingEvent]:
|
||||
return list(
|
||||
db.session.execute(
|
||||
db.select(CameraRecordingEvent)
|
||||
.order_by(CameraRecordingEvent.timestamp.desc())
|
||||
.limit(limit)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user