Browse Source

move shit's

master
gsd 8 months ago
parent
commit
644ca0a8ee
  1. 0
      backend/config_parser.py
  2. 0
      backend/nvr_core.py
  3. 0
      backend/nvr_types.py
  4. 26
      backend/server.py

0
config_parser.py → backend/config_parser.py

0
nvr_core.py → backend/nvr_core.py

0
nvr_types.py → backend/nvr_types.py

26
server.py → backend/server.py

@ -21,7 +21,7 @@ class Server:
print("i am alive")
def setup_routers(self):
@self.app.get("/api/recorders", status_code=200)
@self.app.get("/api", status_code=200)
async def getRecorders(response: Response):
try:
return {"ok":True, "data":self.config.getRecorders()}
@ -30,7 +30,7 @@ class Server:
response.status_code = 400
return {"ok":False, "error":e}
@self.app.get("/api/recorders/{recorder_index}/channels", status_code=200)
@self.app.get("/api/channels/{recorder_index}", status_code=200)
async def getRecorder(response: Response, recorder_index:int):
try:
nvr:NVR = self.config.getRecorder(recorder_index).nvr
@ -44,7 +44,7 @@ class Server:
finally:
nvr.logout()
@self.app.get("/api/recorders/{recorder_index}/{channel}/{stream}")
@self.app.get("/api/history/{recorder_index}/{channel}/{stream}")
async def getHistory(response: Response, recorder_index:int, channel: int, stream: int, start_date:str = None, end_date:str = None):
try:
nvr:NVR = self.config.getRecorder(recorder_index).nvr
@ -57,7 +57,23 @@ class Server:
finally:
nvr.logout()
@self.app.get("/api/recorders/{recorder_index}/file")
@self.app.get("/api/snapshot/{recorder_index}/{channel}")
async def getSnapshot(response: Response, recorder_index:int, channel: int):
try:
nvr:NVR = self.config.getRecorder(recorder_index).nvr
await nvr.login()
async def image():
async for b in await nvr.client.snapshot(channel):
yield b
return StreamingResponse(image(), media_type="image/jpg")
except Exception as e:
traceback.print_exc()
response.status_code = 400
return b""
finally:
nvr.logout()
@self.app.get("/api/file/{recorder_index}")
async def getFile(response: Response, recorder_index:int, b64:str, background_tasks: BackgroundTasks):
try:
if len(b64) == 0:
@ -77,7 +93,7 @@ class Server:
nvr.logout()
background_tasks.add_task(after)
return StreamingResponse(nvr.stream_file(file), media_type="application/octet-stream")
return StreamingResponse(nvr.stream_file(file), media_type="application/octet-stream", headers={"Content-Length":file.size})
except Exception as e:
traceback.print_exc()
response.status_code = 400
Loading…
Cancel
Save