Browse Source

preview load timeout fix 4

master
gsd 7 months ago
parent
commit
446e217538
  1. 15
      backend/config_parser.py
  2. 2
      backend/server.py

15
backend/config_parser.py

@ -281,6 +281,13 @@ class TranscodeTools:
raw_file = file.previewPath(self.transcode_directory)
preview_file = f"{raw_file}.{ext}"
def clear_from_storage():
try:
idx = self.preview_storage.index(preview_file)
del self.preview_storage[idx]
except:
self.preview_storage = []
if preview_file in self.preview_storage:
return preview_file
else:
@ -291,6 +298,7 @@ class TranscodeTools:
return preview_file
if nvr is None:
clear_from_storage()
raise NeedNVR
if not os.path.exists(raw_file) or os.path.getsize(raw_file) == 0:
@ -301,12 +309,7 @@ class TranscodeTools:
async for chunk in nvr.stream_file(file, preview_pre_bytes):
await raw.write(chunk)
except asyncio.TimeoutError as te:
try:
idx = self.preview_storage.index(preview_file)
del self.preview_storage[idx]
except:
self.preview_storage = []
clear_from_storage()
self.logger.info(f"Cancel download file: {te}")
if os.path.exists(raw_file):
os.remove(raw_file)

2
backend/server.py

@ -248,6 +248,8 @@ class Server:
headers = {}
try:
headers.update({"Content-Length":str(os.path.getsize(preview))})
if headers["Content-Length"] == 0:
raise NeedNVR
except:
raise NeedNVR

Loading…
Cancel
Save