Merge branch 'main' of github.com:Monadical-SAS/reflector into sara/recorder-memory

This commit is contained in:
Sara
2023-10-13 19:10:55 +02:00
17 changed files with 333 additions and 291 deletions

View File

@@ -38,7 +38,9 @@ def _get_range_header(range_header: str, file_size: int) -> tuple[int, int]:
return start, end
def range_requests_response(request: Request, file_path: str, content_type: str):
def range_requests_response(
request: Request, file_path: str, content_type: str, content_disposition: str
):
"""Returns StreamingResponse using Range Requests of a given file"""
file_size = os.stat(file_path).st_size
@@ -54,6 +56,10 @@ def range_requests_response(request: Request, file_path: str, content_type: str)
"content-range, content-encoding"
),
}
if content_disposition:
headers["Content-Disposition"] = content_disposition
start = 0
end = file_size - 1
status_code = status.HTTP_200_OK

View File

@@ -356,10 +356,14 @@ async def transcript_get_audio_mp3(
if not transcript.audio_mp3_filename.exists():
raise HTTPException(status_code=404, detail="Audio not found")
truncated_id = str(transcript.id).split("-")[0]
filename = f"recording_{truncated_id}.mp3"
return range_requests_response(
request,
transcript.audio_mp3_filename,
content_type="audio/mp3",
content_type="audio/mpeg",
content_disposition=f"attachment; filename={filename}",
)