|
|
@ -228,7 +228,7 @@ class Server: |
|
|
|
response.status_code = 400 |
|
|
|
return {"ok":False, "error":e} |
|
|
|
@self.app.get(self.API_BASE_REF + "/preview/{recorder_index}") |
|
|
|
async def getTranscodePreview(response: Response, recorder_index:int, b64:str): |
|
|
|
async def getTranscodePreview(response: Response, recorder_index:int, b64:str, background_tasks: BackgroundTasks): |
|
|
|
try: |
|
|
|
if len(b64) == 0: |
|
|
|
response.status_code = 404 |
|
|
@ -236,17 +236,20 @@ class Server: |
|
|
|
|
|
|
|
file: File = File.from_b64(b64 + "==") |
|
|
|
|
|
|
|
try: |
|
|
|
preview = await self.config.transcode_tools.processing_preview(file, None, "webp") |
|
|
|
except NeedNVR: |
|
|
|
async def loadPreview(file): |
|
|
|
nvr:NVR = self.config.getRecorder(recorder_index).nvr |
|
|
|
await nvr.login() |
|
|
|
preview = await self.config.transcode_tools.processing_preview(file, nvr, "webp") |
|
|
|
await self.config.transcode_tools.processing_preview(file, nvr, "webp") |
|
|
|
|
|
|
|
headers = {} |
|
|
|
headers.update({"Content-Length":str(os.path.getsize(preview))}) |
|
|
|
headers.update({"Content-Disposition": f'attachment; filename="preview.webp"'}) |
|
|
|
return FileResponse(preview, media_type="application/octet-stream", headers=headers) |
|
|
|
try: |
|
|
|
preview = await self.config.transcode_tools.processing_preview(file, None, "webp") |
|
|
|
headers = {} |
|
|
|
headers.update({"Content-Length":str(os.path.getsize(preview))}) |
|
|
|
headers.update({"Content-Disposition": f'attachment; filename="preview.webp"'}) |
|
|
|
return FileResponse(preview, media_type="application/octet-stream", headers=headers) |
|
|
|
except NeedNVR: |
|
|
|
background_tasks.add_task(loadPreview, file = file) |
|
|
|
return FileResponse("./assets/loading.webp") |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
traceback.print_exc() |
|
|
|