Skip to content

Commit

Permalink
fix(backend): issue with response codes on various download routes
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <jordanshatford@live.com>
  • Loading branch information
jordanshatford committed Aug 26, 2023
1 parent 3f13c5c commit 3f390fc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
4 changes: 3 additions & 1 deletion backend/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def get_request_session(credentials: HTTPBearerCredentials) -> Session:
}


def get_request_download(video_id: str, session: DependsSession) -> YoutubeDownloadThread: # noqa: E501
def get_request_download(
video_id: str, session: DependsSession,
) -> YoutubeDownloadThread:
download = session.download_manager.get(video_id)
if download is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
Expand Down
23 changes: 14 additions & 9 deletions backend/app/routers/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sse_starlette.sse import EventSourceResponse

from ..dependencies import depends_download_responses
from ..dependencies import depends_session_responses
from ..dependencies import DependsDownload
from ..dependencies import DependsSession
from ..models import StatusUpdate
Expand All @@ -20,7 +21,7 @@
router = APIRouter(
prefix='/downloads',
tags=['downloads'],
responses=depends_download_responses,
responses=depends_session_responses,
)


Expand Down Expand Up @@ -60,13 +61,14 @@ async def get_downloads_status(request: Request, session_id: str):
return EventSourceResponse(event_source)


@router.get('/{video_id}')
@router.get('/{video_id}', responses=depends_download_responses)
def get_download(download: DependsDownload) -> Video:
return download.video


@router.get(
'/{video_id}/file', response_class=FileResponse, responses={
**depends_download_responses,
status.HTTP_200_OK: {
'content': {'audio/*': {'schema': {'type': 'file'}}},
},
Expand All @@ -79,14 +81,17 @@ def get_download_file(download: DependsDownload):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)


@router.get('/{video_id}/status')
@router.get('/{video_id}/status', responses=depends_download_responses)
def get_download_status(download: DependsDownload) -> StatusUpdate:
return StatusUpdate(id=download.video.id, status=download.status)


@router.delete('/{video_id}', status_code=status.HTTP_204_NO_CONTENT)
def delete_download(video_id: str, session: DependsSession) -> None:
if video_id in session.download_manager:
session.download_manager.remove(video_id)
else:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
@router.delete(
'/{video_id}', status_code=status.HTTP_204_NO_CONTENT,
responses=depends_download_responses,
)
def delete_download(
download: DependsDownload,
session: DependsSession,
) -> None:
session.download_manager.remove(download.video.id)
5 changes: 4 additions & 1 deletion backend/app/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@


@router.get('')
def get_search(session: DependsSession, term: str, results: int = 12) -> list[Video]: # noqa: E501
def get_search(
session: DependsSession, term: str,
results: int = 12,
) -> list[Video]:
session.update_use_time()
videos = search_youtube(term, results)
if len(videos) == 0:
Expand Down
5 changes: 4 additions & 1 deletion backend/app/utils/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@


class AudioDownloadManager:
def __init__(self, output_dir: str, announcer: Callable[[str, Status], None]): # noqa: E501
def __init__(
self, output_dir: str,
announcer: Callable[[str, Status], None],
):
self._announcer = announcer
self._downloads: dict[str, YoutubeDownloadThread] = {}
self._output_dir = output_dir
Expand Down
6 changes: 0 additions & 6 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
},
"security": [
Expand Down Expand Up @@ -167,9 +164,6 @@
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
},
"422": {
"description": "Validation Error",
"content": {
Expand Down

0 comments on commit 3f390fc

Please sign in to comment.