mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
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:
@@ -34,6 +34,7 @@ async def transcript_get_audio_mp3(
|
|||||||
request: Request,
|
request: Request,
|
||||||
transcript_id: str,
|
transcript_id: str,
|
||||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
||||||
|
session: AsyncSession = Depends(get_session),
|
||||||
token: str | None = None,
|
token: str | None = None,
|
||||||
):
|
):
|
||||||
user_id = user["sub"] if user else None
|
user_id = user["sub"] if user else None
|
||||||
@@ -88,7 +89,7 @@ async def transcript_get_audio_mp3(
|
|||||||
|
|
||||||
return range_requests_response(
|
return range_requests_response(
|
||||||
request,
|
request,
|
||||||
transcript.audio_mp3_filename,
|
transcript.audio_mp3_filename.as_posix(),
|
||||||
content_type="audio/mpeg",
|
content_type="audio/mpeg",
|
||||||
content_disposition=f"attachment; filename={filename}",
|
content_disposition=f"attachment; filename={filename}",
|
||||||
)
|
)
|
||||||
@@ -108,4 +109,8 @@ async def transcript_get_audio_waveform(
|
|||||||
if not transcript.audio_waveform_filename.exists():
|
if not transcript.audio_waveform_filename.exists():
|
||||||
raise HTTPException(status_code=404, detail="Audio not found")
|
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
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ def celery_includes():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def client():
|
async def client(db_session):
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
from reflector.app import app
|
from reflector.app import app
|
||||||
@@ -364,7 +364,7 @@ def fake_mp3_upload():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def fake_transcript_with_topics(tmpdir, client):
|
async def fake_transcript_with_topics(tmpdir, client, db_session):
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ async def fake_transcript_with_topics(tmpdir, client):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
tid = response.json()["id"]
|
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
|
assert transcript is not None
|
||||||
|
|
||||||
await transcripts_controller.update(transcript, {"status": "ended"})
|
await transcripts_controller.update(transcript, {"status": "ended"})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import pytest
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def fake_transcript(tmpdir, client):
|
async def fake_transcript(tmpdir, client, db_session):
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
from reflector.views.transcripts import transcripts_controller
|
from reflector.views.transcripts import transcripts_controller
|
||||||
|
|
||||||
@@ -16,10 +16,10 @@ async def fake_transcript(tmpdir, client):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
tid = response.json()["id"]
|
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
|
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
|
# manually copy a file at the expected location
|
||||||
audio_filename = transcript.audio_mp3_filename
|
audio_filename = transcript.audio_mp3_filename
|
||||||
|
|||||||
Reference in New Issue
Block a user