Browse Source

pre pre alpha

master
gsd 8 months ago
parent
commit
309ebc3413
  1. 7
      backend/nvr_types.py
  2. 2
      backend/server.py

7
backend/nvr_types.py

@ -5,6 +5,8 @@ import struct
import base64
NVR_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
NVR_TIME_FORMAT = "%H:%M:%S"
NVR_DATE_FORMAT = "%Y-%m-%d"
PRIMARY_STREAM = 0
SECONDARY_STREAM = 1
@ -22,9 +24,10 @@ class File:
self.SerialNo = data.get("SerialNo")
self.size = int(data.get("FileLength"), 0) * 1024 if "FileLength" in data else data.get("size", 0)
self.filename = data.get("FileName", data.get("filename"))
self.filename_cleared = self.filename.split("/")[-1].replace("[", "_").replace("]", "_").replace("@","_")
self.channel = channel
self.stream = stream
self.type = "h264"
self.filename_cleared = f"{self.begin.strftime(NVR_DATE_FORMAT)} {self.begin.strftime(NVR_TIME_FORMAT)} - {self.end.strftime(NVR_TIME_FORMAT)} ({self.channel}) ({self.stream})"
def __str__(self) -> str:
return f"{self.filename_cleared}/{self.size}/{self.channel}/{self.stream}"
@ -41,7 +44,7 @@ class File:
@property
def json(self):
return {"filename": self.filename_cleared, "size": self.size, "b64": self.to_b64.replace("==", "")}
return {"filename": self.filename_cleared, "type": self.type, "size": self.size, "b64": self.to_b64.replace("==", "")}
@staticmethod
def from_b64(b64):

2
backend/server.py

@ -96,7 +96,7 @@ class Server:
background_tasks.add_task(after)
headers = {}
headers.update({"Content-Length":str(file.size)})
headers.update({"Content-Disposition": f'attachment; filename="{file.filename_cleared}"'})
headers.update({"Content-Disposition": f'attachment; filename="{file.filename_cleared}.{file.type}"'})
return StreamingResponse(nvr.stream_file(file), media_type="application/octet-stream", headers=headers)
except Exception as e:
traceback.print_exc()

Loading…
Cancel
Save