Fix edge case where browser sends multiple requests to download file.

This commit is contained in:
Nick Mowen 2022-09-07 16:25:06 -06:00 committed by Blake Blackshear
parent b6f799e641
commit 7e9f913ff6

View File

@ -786,33 +786,38 @@ def recording_clip(camera_name, start_ts, end_ts):
file_name = f"clip_{camera_name}_{start_ts}-{end_ts}.mp4" file_name = f"clip_{camera_name}_{start_ts}-{end_ts}.mp4"
path = f"/tmp/cache/{file_name}" path = f"/tmp/cache/{file_name}"
ffmpeg_cmd = [ if not os.path.exists(path):
"ffmpeg", ffmpeg_cmd = [
"-y", "ffmpeg",
"-protocol_whitelist", "-y",
"pipe,file", "-protocol_whitelist",
"-f", "pipe,file",
"concat", "-f",
"-safe", "concat",
"0", "-safe",
"-i", "0",
"/dev/stdin", "-i",
"-c", "/dev/stdin",
"copy", "-c",
"-movflags", "copy",
"+faststart", "-movflags",
path, "+faststart",
] path,
]
p = sp.run(
ffmpeg_cmd,
input="\n".join(playlist_lines),
encoding="ascii",
capture_output=True,
)
p = sp.run( if p.returncode != 0:
ffmpeg_cmd, logger.error(p.stderr)
input="\n".join(playlist_lines), return f"Could not create clip from recordings for {camera_name}.", 500
encoding="ascii", else:
capture_output=True, logger.debug(
) f"Ignoring subsequent request for {path} as it already exists in the cache."
if p.returncode != 0: )
logger.error(p.stderr)
return f"Could not create clip from recordings for {camera_name}.", 500
response = make_response() response = make_response()
response.headers["Content-Description"] = "File Transfer" response.headers["Content-Description"] = "File Transfer"