|
|
|
@ -74,15 +74,14 @@ class SaveWordRequest(BaseModel):
|
|
|
|
|
|
|
|
|
|
@app.post("/api/save-word")
|
|
|
|
|
async def save_to_word(request: Request):
|
|
|
|
|
temp_html = None
|
|
|
|
|
output_file = None
|
|
|
|
|
try:
|
|
|
|
|
# Parse request data
|
|
|
|
|
try:
|
|
|
|
|
data = await request.json()
|
|
|
|
|
html_content = data.get('html_content', '')
|
|
|
|
|
if not html_content:
|
|
|
|
|
raise ValueError("Empty HTML content")
|
|
|
|
|
markdown_content = data.get('markdown_content', '')
|
|
|
|
|
if not markdown_content:
|
|
|
|
|
raise ValueError("Empty MarkDown content")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Request parsing failed: {str(e)}")
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Invalid request: {str(e)}")
|
|
|
|
@ -90,7 +89,7 @@ async def save_to_word(request: Request):
|
|
|
|
|
# 创建临时Markdown文件
|
|
|
|
|
temp_md = os.path.join(tempfile.gettempdir(), uuid.uuid4().hex + ".md")
|
|
|
|
|
with open(temp_md, "w", encoding="utf-8") as f:
|
|
|
|
|
f.write(html_content)
|
|
|
|
|
f.write(markdown_content)
|
|
|
|
|
|
|
|
|
|
# 使用pandoc转换
|
|
|
|
|
output_file = os.path.join(tempfile.gettempdir(), "【理想大模型】问答.docx")
|
|
|
|
|