fix: add missing db_session parameter to transcript audio endpoints

- Add db_session parameter to transcript_get_audio_mp3 endpoint
- Fix audio_mp3_filename path conversion with .as_posix()
- Add null check for audio_waveform before returning
- Update test fixtures to properly pass db_session parameter
- Fix transcript controller calls in test_transcripts_audio_download
This commit is contained in:
2025-09-23 19:05:50 -06:00
parent ad2accb574
commit df909363f5
3 changed files with 13 additions and 8 deletions

View File

@@ -34,6 +34,7 @@ async def transcript_get_audio_mp3(
request: Request,
transcript_id: str,
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
session: AsyncSession = Depends(get_session),
token: str | None = None,
):
user_id = user["sub"] if user else None
@@ -88,7 +89,7 @@ async def transcript_get_audio_mp3(
return range_requests_response(
request,
transcript.audio_mp3_filename,
transcript.audio_mp3_filename.as_posix(),
content_type="audio/mpeg",
content_disposition=f"attachment; filename={filename}",
)
@@ -108,4 +109,8 @@ async def transcript_get_audio_waveform(
if not transcript.audio_waveform_filename.exists():
raise HTTPException(status_code=404, detail="Audio not found")
return transcript.audio_waveform
audio_waveform = transcript.audio_waveform
if not audio_waveform:
raise HTTPException(status_code=404, detail="Audio waveform not found")
return audio_waveform

View File

@@ -345,7 +345,7 @@ def celery_includes():
@pytest.fixture
async def client():
async def client(db_session):
from httpx import AsyncClient
from reflector.app import app
@@ -364,7 +364,7 @@ def fake_mp3_upload():
@pytest.fixture
async def fake_transcript_with_topics(tmpdir, client):
async def fake_transcript_with_topics(tmpdir, client, db_session):
import shutil
from pathlib import Path
@@ -380,7 +380,7 @@ async def fake_transcript_with_topics(tmpdir, client):
assert response.status_code == 200
tid = response.json()["id"]
transcript = await transcripts_controller.get_by_id(tid)
transcript = await transcripts_controller.get_by_id(db_session, tid)
assert transcript is not None
await transcripts_controller.update(transcript, {"status": "ended"})

View File

@@ -5,7 +5,7 @@ import pytest
@pytest.fixture
async def fake_transcript(tmpdir, client):
async def fake_transcript(tmpdir, client, db_session):
from reflector.settings import settings
from reflector.views.transcripts import transcripts_controller
@@ -16,10 +16,10 @@ async def fake_transcript(tmpdir, client):
assert response.status_code == 200
tid = response.json()["id"]
transcript = await transcripts_controller.get_by_id(tid)
transcript = await transcripts_controller.get_by_id(db_session, tid)
assert transcript is not None
await transcripts_controller.update(transcript, {"status": "ended"})
await transcripts_controller.update(db_session, transcript, {"status": "ended"})
# manually copy a file at the expected location
audio_filename = transcript.audio_mp3_filename