Spaces:
Paused
Paused
revert md request
Browse files- file_conversion.py +0 -40
file_conversion.py
CHANGED
|
@@ -95,46 +95,6 @@ async def convert_html_to_docx(background_tasks: BackgroundTasks, request: HTMLR
|
|
| 95 |
try:
|
| 96 |
html_to_pdf(request.html_content, pdf_temp_path)
|
| 97 |
return handle_conversion(pdf_to_docx, pdf_temp_path, docx_temp_path, background_tasks)
|
| 98 |
-
except Exception as e:
|
| 99 |
-
remove_file(pdf_temp_path)
|
| 100 |
-
remove_file(docx_temp_path)
|
| 101 |
-
raise HTTPException(status_code=500, detail=f"Conversion failed: {str(e)}")
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
import markdown
|
| 105 |
-
|
| 106 |
-
class MarkdownRequest(BaseModel):
|
| 107 |
-
markdown_content: str
|
| 108 |
-
|
| 109 |
-
def markdown_to_html(markdown_content: str) -> str:
|
| 110 |
-
return markdown.markdown(markdown_content)
|
| 111 |
-
|
| 112 |
-
@router.post("/convert/md_to_pdf")
|
| 113 |
-
async def convert_md_to_pdf(request: MarkdownRequest):
|
| 114 |
-
ensure_temp_dir()
|
| 115 |
-
pdf_temp_path = generate_temp_filepath("pdf")
|
| 116 |
-
|
| 117 |
-
try:
|
| 118 |
-
html_content = markdown_to_html(request.markdown_content)
|
| 119 |
-
html_to_pdf(html_content, pdf_temp_path)
|
| 120 |
-
with open(pdf_temp_path, "rb") as pdf_file:
|
| 121 |
-
pdf_content = pdf_file.read()
|
| 122 |
-
remove_file(pdf_temp_path)
|
| 123 |
-
return Response(content=pdf_content, media_type="application/pdf")
|
| 124 |
-
except Exception as e:
|
| 125 |
-
remove_file(pdf_temp_path)
|
| 126 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 127 |
-
|
| 128 |
-
@router.post("/convert/md_to_docx")
|
| 129 |
-
async def convert_md_to_docx(background_tasks: BackgroundTasks, request: MarkdownRequest):
|
| 130 |
-
ensure_temp_dir()
|
| 131 |
-
pdf_temp_path = generate_temp_filepath("pdf")
|
| 132 |
-
docx_temp_path = pdf_temp_path.replace('.pdf', '.docx')
|
| 133 |
-
|
| 134 |
-
try:
|
| 135 |
-
html_content = markdown_to_html(request.markdown_content)
|
| 136 |
-
html_to_pdf(html_content, pdf_temp_path)
|
| 137 |
-
return handle_conversion(pdf_to_docx, pdf_temp_path, docx_temp_path, background_tasks)
|
| 138 |
except Exception as e:
|
| 139 |
remove_file(pdf_temp_path)
|
| 140 |
remove_file(docx_temp_path)
|
|
|
|
| 95 |
try:
|
| 96 |
html_to_pdf(request.html_content, pdf_temp_path)
|
| 97 |
return handle_conversion(pdf_to_docx, pdf_temp_path, docx_temp_path, background_tasks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
except Exception as e:
|
| 99 |
remove_file(pdf_temp_path)
|
| 100 |
remove_file(docx_temp_path)
|