Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kompoth committed Apr 1, 2024
1 parent 6ffbe18 commit 9a1ef6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion muckraker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
)


@app.post("/issue")
@app.post("/issue/")
async def create_issue(issue: Issue):
with tempfile.TemporaryDirectory() as tempdir:
# Render PDF and save it in the tempdir
pdf_tmp_path = Path(tempdir) / "out.pdf"
render_issue(issue.config.model_dump(), issue.body, pdf_tmp_path)

# Save PDF to the buffer
with open(pdf_tmp_path, "rb") as fd:
buf = BytesIO(fd.read())

# Get it from the buffer
pdf_bytes = buf.getvalue()
buf.close()

headers = {'Content-Disposition': 'attachment; filename="out.pdf"'}
return Response(pdf_bytes, headers=headers, media_type='application/pdf')
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Markdown==3.6
Jinja2==3.1.3
weasyprint==61.2
pydantic==2.6.4
nh3==0.2.17
fastapi==0.110.0
uvicorn==0.29.0
httpx==0.26.0
Jinja2==3.1.3
Markdown==3.6
nh3==0.2.17
pydantic==2.6.4
pytest==8.1.1
uvicorn==0.29.0
weasyprint==61.2

0 comments on commit 9a1ef6e

Please sign in to comment.