Skip to content

Commit

Permalink
simplify attach files
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorsilverio committed Sep 27, 2021
1 parent 91db04b commit 2a64a79
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi.responses import Response
from fastapi.responses import StreamingResponse

from app.util import attach_file
from libraryapi.pergamum import PergamumDownloader


Expand All @@ -14,7 +15,7 @@ async def get_marc(url: str, id: int) -> StreamingResponse:
response = StreamingResponse(
pergamumDownloader.download_iso(url, id), media_type="application/marc"
)
response.headers["Content-Disposition"] = f"attachment; filename={id}.mrc"
attach_file(response, id, "mrc")
return response


Expand All @@ -23,5 +24,5 @@ async def get_marcxml(url: str, id: int) -> Response:
response = Response(
pergamumDownloader.download_xml(url, id), media_type="application/xml"
)
response.headers["Content-Disposition"] = f"attachment; filename={id}.xml"
attach_file(response, id, "xml")
return response
4 changes: 4 additions & 0 deletions app/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def attach_file(response, name, extension):
response.headers[
"Content-Disposition"
] = f"attachment; filename={name}.{extension}"

0 comments on commit 2a64a79

Please sign in to comment.